From 244996ffec3b76c4cbef2e9684c0557ffed7e8fa Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Sat, 30 Sep 2000 00:17:22 +0000 Subject: fix indentation 2000-09-29 Havoc Pennington * gtk/gtktexttag.c (gtk_text_tag_set_priority): fix indentation * gtk/gtktextview.c: Implement drag thresholding; change functions that set border window size to have nicer name (gtk_text_view_mark_set_handler): Fix this to have the right signature. * gtk/testtextbuffer.c (fill_buffer): Update with pixbuf changes * gtk/testtext.c: Update with API changes, put line numbers on both sides. * gtk/gtktextiter.c (gtk_text_iter_get_pixbuf): Replace get_pixmap with this * gtk/gtktextchild.h, gtk/gtktextchild.c: replace all pixmap with pixbuf; delete a big block of #if 0 Tk code * gtk/gtktextbuffer.c (gtk_text_buffer_insert_pixbuf): Replace insert_pixmap with insert_pixbuf --- gtk/gtktextbtree.c | 11 +- gtk/gtktextbtree.h | 5 +- gtk/gtktextbuffer.c | 39 +- gtk/gtktextbuffer.h | 12 +- gtk/gtktextchild.c | 1218 ++------------------------------------------------ gtk/gtktextchild.h | 9 +- gtk/gtktextdisplay.c | 100 +++-- gtk/gtktextiter.c | 42 +- gtk/gtktextiter.h | 8 +- gtk/gtktextlayout.c | 18 +- gtk/gtktextlayout.h | 4 +- gtk/gtktextmark.c | 4 +- gtk/gtktextmark.h | 18 +- gtk/gtktextsegment.h | 2 +- gtk/gtktexttag.c | 54 +-- gtk/gtktexttypes.h | 2 +- gtk/gtktextview.c | 198 ++++++-- gtk/gtktextview.h | 30 +- gtk/testtext.c | 316 +++++++++---- gtk/testtextbuffer.c | 30 +- 20 files changed, 622 insertions(+), 1498 deletions(-) (limited to 'gtk') diff --git a/gtk/gtktextbtree.c b/gtk/gtktextbtree.c index ca40609951..468d5ccaa1 100644 --- a/gtk/gtktextbtree.c +++ b/gtk/gtktextbtree.c @@ -1043,9 +1043,8 @@ gtk_text_btree_insert (GtkTextIter *iter, } void -gtk_text_btree_insert_pixmap (GtkTextIter *iter, - GdkPixmap *pixmap, - GdkBitmap *mask) +gtk_text_btree_insert_pixbuf (GtkTextIter *iter, + GdkPixbuf *pixbuf) { GtkTextLineSegment *seg; GtkTextIter start; @@ -1058,7 +1057,7 @@ gtk_text_btree_insert_pixmap (GtkTextIter *iter, tree = gtk_text_iter_get_btree(iter); start_byte_offset = gtk_text_iter_get_line_index(iter); - seg = gtk_text_pixmap_segment_new (pixmap, mask); + seg = gtk_text_pixbuf_segment_new (pixbuf); prevPtr = gtk_text_line_segment_split(iter); if (prevPtr == NULL) @@ -2037,7 +2036,7 @@ copy_segment(GString *string, /* printf(" :%s\n", string->str); */ } - else if (seg->type == >k_text_pixmap_type) + else if (seg->type == >k_text_pixbuf_type) { gboolean copy = TRUE; @@ -3401,7 +3400,7 @@ gtk_text_line_byte_to_char (GtkTextLine *line, gint gtk_text_line_char_to_byte (GtkTextLine *line, - gint char_offset) + gint char_offset) { g_warning("FIXME not implemented"); } diff --git a/gtk/gtktextbtree.h b/gtk/gtktextbtree.h index 0d6da3ce6d..1f8d6a5899 100644 --- a/gtk/gtktextbtree.h +++ b/gtk/gtktextbtree.h @@ -31,9 +31,8 @@ void gtk_text_btree_delete (GtkTextIter *start, void gtk_text_btree_insert (GtkTextIter *iter, const gchar *text, gint len); -void gtk_text_btree_insert_pixmap (GtkTextIter *iter, - GdkPixmap *pixmap, - GdkBitmap *mask); +void gtk_text_btree_insert_pixbuf (GtkTextIter *iter, + GdkPixbuf *pixbuf); diff --git a/gtk/gtktextbuffer.c b/gtk/gtktextbuffer.c index 1ded48810e..6358e94fe6 100644 --- a/gtk/gtktextbuffer.c +++ b/gtk/gtktextbuffer.c @@ -787,22 +787,21 @@ gtk_text_buffer_get_slice (GtkTextBuffer *buffer, */ void -gtk_text_buffer_insert_pixmap (GtkTextBuffer *buffer, - GtkTextIter *iter, - GdkPixmap *pixmap, - GdkBitmap *mask) +gtk_text_buffer_insert_pixbuf (GtkTextBuffer *buffer, + GtkTextIter *iter, + GdkPixbuf *pixbuf) { - g_return_if_fail(GTK_IS_TEXT_BUFFER(buffer)); - g_return_if_fail(iter != NULL); - g_return_if_fail(pixmap != NULL); - - gtk_text_btree_insert_pixmap(iter, pixmap, mask); + g_return_if_fail (GTK_IS_TEXT_BUFFER(buffer)); + g_return_if_fail (iter != NULL); + g_return_if_fail (GDK_IS_PIXBUF (pixbuf)); + + gtk_text_btree_insert_pixbuf (iter, pixbuf); - /* FIXME pixmap-specific signal like insert_text */ + /* FIXME pixbuf-specific signal like insert_text */ - gtk_signal_emit(GTK_OBJECT(buffer), signals[CHANGED]); + gtk_signal_emit (GTK_OBJECT(buffer), signals[CHANGED]); - gtk_text_buffer_set_modified(buffer, TRUE); + gtk_text_buffer_set_modified (buffer, TRUE); } /* @@ -977,6 +976,22 @@ gtk_text_buffer_get_mark (GtkTextBuffer *buffer, return mark; } +GtkTextMark* +gtk_text_buffer_get_insert (GtkTextBuffer *buffer) +{ + g_return_val_if_fail(GTK_IS_TEXT_BUFFER(buffer), NULL); + + return gtk_text_buffer_get_mark (buffer, "insert"); +} + +GtkTextMark* +gtk_text_buffer_get_selection_bound (GtkTextBuffer *buffer) +{ + g_return_val_if_fail(GTK_IS_TEXT_BUFFER(buffer), NULL); + + return gtk_text_buffer_get_mark (buffer, "selection_bound"); +} + /** * gtk_text_buffer_place_cursor: * @buffer: a #GtkTextBuffer diff --git a/gtk/gtktextbuffer.h b/gtk/gtktextbuffer.h index b58feb62c4..836010eebc 100644 --- a/gtk/gtktextbuffer.h +++ b/gtk/gtktextbuffer.h @@ -133,11 +133,10 @@ gchar *gtk_text_buffer_get_slice (GtkTextBuffer *buffer, const GtkTextIter *end, gboolean include_hidden_chars); -/* Insert a pixmap */ -void gtk_text_buffer_insert_pixmap (GtkTextBuffer *buffer, +/* Insert a pixbuf */ +void gtk_text_buffer_insert_pixbuf (GtkTextBuffer *buffer, GtkTextIter *iter, - GdkPixmap *pixmap, - GdkBitmap *mask); + GdkPixbuf *pixbuf); /* Mark manipulation */ GtkTextMark *gtk_text_buffer_create_mark (GtkTextBuffer *buffer, @@ -149,9 +148,12 @@ void gtk_text_buffer_move_mark (GtkTextBuffer *buffer, const GtkTextIter *where); void gtk_text_buffer_delete_mark (GtkTextBuffer *buffer, GtkTextMark *mark); -GtkTextMark *gtk_text_buffer_get_mark (GtkTextBuffer *buffer, +GtkTextMark* gtk_text_buffer_get_mark (GtkTextBuffer *buffer, const gchar *name); +GtkTextMark* gtk_text_buffer_get_insert (GtkTextBuffer *buffer); +GtkTextMark* gtk_text_buffer_get_selection_bound (GtkTextBuffer *buffer); + /* efficiently move insert and selection_bound to same location */ void gtk_text_buffer_place_cursor (GtkTextBuffer *buffer, diff --git a/gtk/gtktextchild.c b/gtk/gtktextchild.c index 8e9c815f12..cde111384d 100644 --- a/gtk/gtktextchild.c +++ b/gtk/gtktextchild.c @@ -52,23 +52,20 @@ #include "gtktextbtree.h" static GtkTextLineSegment * -pixmap_segment_cleanup_func(GtkTextLineSegment *seg, - GtkTextLine *line) +pixbuf_segment_cleanup_func (GtkTextLineSegment *seg, + GtkTextLine *line) { /* nothing */ return seg; } static int -pixmap_segment_delete_func(GtkTextLineSegment *seg, - GtkTextLine *line, - gboolean tree_gone) +pixbuf_segment_delete_func(GtkTextLineSegment *seg, + GtkTextLine *line, + gboolean tree_gone) { - if (seg->body.pixmap.pixmap) - gdk_pixmap_unref(seg->body.pixmap.pixmap); - - if (seg->body.pixmap.mask) - gdk_bitmap_unref(seg->body.pixmap.mask); + if (seg->body.pixbuf.pixbuf) + g_object_unref(G_OBJECT (seg->body.pixbuf.pixbuf)); g_free(seg); @@ -76,28 +73,28 @@ pixmap_segment_delete_func(GtkTextLineSegment *seg, } static void -pixmap_segment_check_func(GtkTextLineSegment *seg, - GtkTextLine *line) +pixbuf_segment_check_func(GtkTextLineSegment *seg, + GtkTextLine *line) { if (seg->next == NULL) - g_error("pixmap segment is the last segment in a line"); + g_error("pixbuf segment is the last segment in a line"); if (seg->byte_count != 3) - g_error("pixmap segment has byte count of %d", seg->byte_count); - + g_error("pixbuf segment has byte count of %d", seg->byte_count); + if (seg->char_count != 1) - g_error("pixmap segment has char count of %d", seg->char_count); + g_error("pixbuf segment has char count of %d", seg->char_count); } -GtkTextLineSegmentClass gtk_text_pixmap_type = { - "pixmap", /* name */ +GtkTextLineSegmentClass gtk_text_pixbuf_type = { + "pixbuf", /* name */ 0, /* leftGravity */ NULL, /* splitFunc */ - pixmap_segment_delete_func, /* deleteFunc */ - pixmap_segment_cleanup_func, /* cleanupFunc */ + pixbuf_segment_delete_func, /* deleteFunc */ + pixbuf_segment_cleanup_func, /* cleanupFunc */ NULL, /* lineChangeFunc */ - pixmap_segment_check_func /* checkFunc */ + pixbuf_segment_check_func /* checkFunc */ }; @@ -113,17 +110,17 @@ GtkTextLineSegmentClass gtk_text_view_child_type = { }; #endif -#define PIXMAP_SEG_SIZE ((unsigned) (G_STRUCT_OFFSET(GtkTextLineSegment, body) \ - + sizeof(GtkTextPixmap))) +#define PIXBUF_SEG_SIZE ((unsigned) (G_STRUCT_OFFSET(GtkTextLineSegment, body) \ + + sizeof(GtkTextPixbuf))) GtkTextLineSegment * -gtk_text_pixmap_segment_new(GdkPixmap *pixmap, GdkBitmap *mask) +gtk_text_pixbuf_segment_new (GdkPixbuf *pixbuf) { GtkTextLineSegment *seg; - seg = g_malloc(PIXMAP_SEG_SIZE); + seg = g_malloc(PIXBUF_SEG_SIZE); - seg->type = >k_text_pixmap_type; + seg->type = >k_text_pixbuf_type; seg->next = NULL; @@ -131,1174 +128,9 @@ gtk_text_pixmap_segment_new(GdkPixmap *pixmap, GdkBitmap *mask) a 3-byte sequence in UTF-8 */ seg->char_count = 1; - seg->body.pixmap.pixmap = pixmap; - seg->body.pixmap.mask = mask; - - if (pixmap) - gdk_pixmap_ref(pixmap); + seg->body.pixbuf.pixbuf = pixbuf; - if (mask) - gdk_bitmap_ref(mask); + g_object_ref (G_OBJECT (pixbuf)); return seg; } - -#if 0 - -/* - * The following structure is the official type record for the - * embedded window geometry manager: - */ - -static void EmbWinRequestFunc _ANSI_ARGS_((gpointer clientData, - Tk_Window tkwin)); -static void EmbWinLostSlaveFunc _ANSI_ARGS_((gpointer clientData, - Tk_Window tkwin)); - -static Tk_GeomMgr textGeomType = { - "text", /* name */ - EmbWinRequestFunc, /* requestFunc */ - EmbWinLostSlaveFunc, /* lostSlaveFunc */ -}; - -/* - * Definitions for alignment values: - */ - -#define ALIGN_BOTTOM 0 -#define ALIGN_CENTER 1 -#define ALIGN_TOP 2 -#define ALIGN_BASELINE 3 - -/* - * Macro that determines the size of an embedded window segment: - */ - -#define EW_SEG_SIZE ((unsigned) (G_STRUCT_OFFSET(GtkTextLineSegment, body) \ - + sizeof(GtkTextEmbWindow))) - -/* - * Prototypes for procedures defined in this file: - */ - -static int AlignParseFunc _ANSI_ARGS_((gpointer clientData, - Tcl_Interp *interp, Tk_Window tkwin, char *value, - char *widgRec, int offset)); -static char * AlignPrintFunc _ANSI_ARGS_((gpointer clientData, - Tk_Window tkwin, char *widgRec, int offset, - Tcl_FreeFunc **freeFuncPtr)); -static GtkTextLineSegment * EmbWinCleanupFunc _ANSI_ARGS_((GtkTextLineSegment *segPtr, - GtkTextLine *line)); -static void EmbWinCheckFunc _ANSI_ARGS_((GtkTextLineSegment *segPtr, - GtkTextLine *line)); -static void EmbWinBboxFunc _ANSI_ARGS_((GtkTextDisplayChunk *chunkPtr, - int index, int y, int lineHeight, int baseline, - int *xPtr, int *yPtr, int *widthPtr, - int *heightPtr)); -static int EmbWinConfigure _ANSI_ARGS_((GtkTextView *tkxt, - GtkTextLineSegment *ewPtr, int argc, char **argv)); -static void EmbWinDelayedUnmap _ANSI_ARGS_(( - gpointer clientData)); -static int EmbWinDeleteFunc _ANSI_ARGS_((GtkTextLineSegment *segPtr, - GtkTextLine *line, int treeGone)); -static void EmbWinDisplayFunc _ANSI_ARGS_(( - GtkTextDisplayChunk *chunkPtr, int x, int y, - int lineHeight, int baseline, Display *display, - Drawable dst, int screenY)); -static int EmbWinLayoutFunc _ANSI_ARGS_((GtkTextView *tkxt, - GtkTextIndex *indexPtr, GtkTextLineSegment *segPtr, - int offset, int maxX, int maxChars, - int noCharsYet, GtkWrapMode wrapMode, - GtkTextDisplayChunk *chunkPtr)); -static void EmbWinStructureFunc _ANSI_ARGS_((gpointer clientData, - XEvent *eventPtr)); -static void EmbWinUndisplayFunc _ANSI_ARGS_((GtkTextView *tkxt, - GtkTextDisplayChunk *chunkPtr)); - -/* - * The following structure declares the "embedded window" segment type. - */ - -static GtkTextLineSegmentClass tkTextEmbWindowType = { - "window", /* name */ - 0, /* leftGravity */ - (GtkTextLineSegmentSplitFunc *) NULL, /* splitFunc */ - EmbWinDeleteFunc, /* deleteFunc */ - EmbWinCleanupFunc, /* cleanupFunc */ - (GtkTextLineSegmentLineChangeFunc *) NULL, /* lineChangeFunc */ - EmbWinLayoutFunc, /* layoutFunc */ - EmbWinCheckFunc /* checkFunc */ -}; - -/* - * Information used for parsing window configuration options: - */ - -static Tk_CustomOption alignOption = {AlignParseFunc, AlignPrintFunc, - (gpointer) NULL}; - -static Tk_ConfigSpec configSpecs[] = { - {TK_CONFIG_CUSTOM, "-align", (char *) NULL, (char *) NULL, - "center", 0, TK_CONFIG_DONT_SET_DEFAULT, &alignOption}, - {TK_CONFIG_STRING, "-create", (char *) NULL, (char *) NULL, - (char *) NULL, G_STRUCT_OFFSET(GtkTextEmbWindow, create), - TK_CONFIG_DONT_SET_DEFAULT|TK_CONFIG_NULL_OK}, - {TK_CONFIG_INT, "-padx", (char *) NULL, (char *) NULL, - "0", G_STRUCT_OFFSET(GtkTextEmbWindow, padX), - TK_CONFIG_DONT_SET_DEFAULT}, - {TK_CONFIG_INT, "-pady", (char *) NULL, (char *) NULL, - "0", G_STRUCT_OFFSET(GtkTextEmbWindow, padY), - TK_CONFIG_DONT_SET_DEFAULT}, - {TK_CONFIG_BOOLEAN, "-stretch", (char *) NULL, (char *) NULL, - "0", G_STRUCT_OFFSET(GtkTextEmbWindow, stretch), - TK_CONFIG_DONT_SET_DEFAULT}, - {TK_CONFIG_WINDOW, "-window", (char *) NULL, (char *) NULL, - (char *) NULL, G_STRUCT_OFFSET(GtkTextEmbWindow, tkwin), - TK_CONFIG_DONT_SET_DEFAULT|TK_CONFIG_NULL_OK}, - {TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL, - (char *) NULL, 0, 0} -}; - -/* - *-------------------------------------------------------------- - * - * GtkTextViewWindowCmd -- - * - * This procedure implements the "window" widget command - * for text widgets. See the user documentation for details - * on what it does. - * - * Results: - * A standard Tcl result or error. - * - * Side effects: - * See the user documentation. - * - *-------------------------------------------------------------- - */ - -int -GtkTextViewWindowCmd(tkxt, interp, argc, argv) - GtkTextView *tkxt; /* Information about text widget. */ - Tcl_Interp *interp; /* Current interpreter. */ - int argc; /* Number of arguments. */ - char **argv; /* Argument strings. Someone else has already - * parsed this command enough to know that - * argv[1] is "window". */ -{ - size_t length; - GtkTextLineSegment *ewPtr; - - if (argc < 3) { - Tcl_AppendResult(interp, "wrong # args: should be \"", - argv[0], " window option ?arg arg ...?\"", (char *) NULL); - return TCL_ERROR; - } - length = strlen(argv[2]); - if ((strncmp(argv[2], "cget", length) == 0) && (length >= 2)) { - GtkTextIndex index; - GtkTextLineSegment *ewPtr; - - if (argc != 5) { - Tcl_AppendResult(interp, "wrong # args: should be \"", - argv[0], " window cget index option\"", - (char *) NULL); - return TCL_ERROR; - } - if (gtk_text_btree_index_from_string(interp, tkxt, argv[3], &index) != TCL_OK) { - return TCL_ERROR; - } - ewPtr = gtk_text_view_index_to_seg(&index, (int *) NULL); - if (ewPtr->type != &tkTextEmbWindowType) { - Tcl_AppendResult(interp, "no embedded window at index \"", - argv[3], "\"", (char *) NULL); - return TCL_ERROR; - } - return Tk_ConfigureValue(interp, tkxt->tkwin, configSpecs, - (char *) &ewPtr->body.ew, argv[4], 0); - } else if ((strncmp(argv[2], "configure", length) == 0) && (length >= 2)) { - GtkTextIndex index; - GtkTextLineSegment *ewPtr; - - if (argc < 4) { - Tcl_AppendResult(interp, "wrong # args: should be \"", - argv[0], " window configure index ?option value ...?\"", - (char *) NULL); - return TCL_ERROR; - } - if (gtk_text_btree_index_from_string(interp, tkxt, argv[3], &index) != TCL_OK) { - return TCL_ERROR; - } - ewPtr = gtk_text_view_index_to_seg(&index, (int *) NULL); - if (ewPtr->type != &tkTextEmbWindowType) { - Tcl_AppendResult(interp, "no embedded window at index \"", - argv[3], "\"", (char *) NULL); - return TCL_ERROR; - } - if (argc == 4) { - return Tk_ConfigureInfo(interp, tkxt->tkwin, configSpecs, - (char *) &ewPtr->body.ew, (char *) NULL, 0); - } else if (argc == 5) { - return Tk_ConfigureInfo(interp, tkxt->tkwin, configSpecs, - (char *) &ewPtr->body.ew, argv[4], 0); - } else { - gtk_text_buffer_need_redisplay(tree->buffer, &index, &index); - return EmbWinConfigure(tkxt, ewPtr, argc-4, argv+4); - } - } else if ((strncmp(argv[2], "create", length) == 0) && (length >= 2)) { - GtkTextIndex index; - int lineIndex; - - /* - * Add a new window. Find where to put the new window, and - * mark that position for redisplay. - */ - - if (argc < 4) { - Tcl_AppendResult(interp, "wrong # args: should be \"", - argv[0], " window create index ?option value ...?\"", - (char *) NULL); - return TCL_ERROR; - } - if (gtk_text_btree_index_from_string(interp, tkxt, argv[3], &index) != TCL_OK) { - return TCL_ERROR; - } - - /* - * Don't allow insertions on the last (dummy) line of the text. - */ - - lineIndex = gtk_text_btree_line_number(index.line); - if (lineIndex == gtk_text_btree_num_lines(tkxt->tree)) { - lineIndex--; - gtk_text_btree_get_line_byte_index(tkxt->tree, lineIndex, G_MAXINT, &index); - } - - /* - * Create the new window segment and initialize it. - */ - - ewPtr = (GtkTextLineSegment *) g_malloc(EW_SEG_SIZE); - ewPtr->type = &tkTextEmbWindowType; - ewPtr->size = 1; - ewPtr->body.ew.tkxt = tkxt; - ewPtr->body.ew.line = NULL; - ewPtr->body.ew.tkwin = NULL; - ewPtr->body.ew.create = NULL; - ewPtr->body.ew.align = ALIGN_CENTER; - ewPtr->body.ew.padX = ewPtr->body.ew.padY = 0; - ewPtr->body.ew.stretch = 0; - ewPtr->body.ew.chunkCount = 0; - ewPtr->body.ew.displayed = 0; - - /* - * Link the segment into the text widget, then configure it (delete - * it again if the configuration fails). - */ - - gtk_text_buffer_need_redisplay(tkxt, &index, &index); - gtk_text_btree_link_segment(ewPtr, &index); - if (EmbWinConfigure(tkxt, ewPtr, argc-4, argv+4) != TCL_OK) { - GtkTextIndex index2; - - gtk_text_view_index_forw_chars(&index, 1, &index2); - gtk_text_btree_delete_chars(&index, &index2); - return TCL_ERROR; - } - } else if (strncmp(argv[2], "names", length) == 0) { - Tcl_HashSearch search; - Tcl_HashEntry *hPtr; - - if (argc != 3) { - Tcl_AppendResult(interp, "wrong # args: should be \"", - argv[0], " window names\"", (char *) NULL); - return TCL_ERROR; - } - for (hPtr = Tcl_FirstHashEntry(&tkxt->windowTable, &search); - hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) { - Tcl_AppendElement(interp, - Tcl_GetHashKey(&tkxt->markTable, hPtr)); - } - } else { - Tcl_AppendResult(interp, "bad window option \"", argv[2], - "\": must be cget, configure, create, or names", - (char *) NULL); - return TCL_ERROR; - } - return TCL_OK; -} - -/* - *-------------------------------------------------------------- - * - * EmbWinConfigure -- - * - * This procedure is called to handle configuration options - * for an embedded window, using an argc/argv list. - * - * Results: - * The return value is a standard Tcl result. If TCL_ERROR is - * returned, then the interp's result contains an error message.. - * - * Side effects: - * Configuration information for the embedded window changes, - * such as alignment, stretching, or name of the embedded - * window. - * - *-------------------------------------------------------------- - */ - -static int -EmbWinConfigure(tkxt, ewPtr, argc, argv) - GtkTextView *tkxt; /* Information about text widget that - * contains embedded window. */ - GtkTextLineSegment *ewPtr; /* Embedded window to be configured. */ - int argc; /* Number of strings in argv. */ - char **argv; /* Array of strings describing configuration - * options. */ -{ - Tk_Window oldWindow; - Tcl_HashEntry *hPtr; - int new; - - oldWindow = ewPtr->body.ew.tkwin; - if (Tk_ConfigureWidget(tkxt->interp, tkxt->tkwin, configSpecs, - argc, argv, (char *) &ewPtr->body.ew, TK_CONFIG_ARGV_ONLY) - != TCL_OK) { - return TCL_ERROR; - } - if (oldWindow != ewPtr->body.ew.tkwin) { - if (oldWindow != NULL) { - Tcl_DeleteHashEntry(Tcl_FindHashEntry(&tkxt->windowTable, - Tk_PathName(oldWindow))); - Tk_DeleteEventHandler(oldWindow, StructureNotifyMask, - EmbWinStructureFunc, (gpointer) ewPtr); - Tk_ManageGeometry(oldWindow, (Tk_GeomMgr *) NULL, - (gpointer) NULL); - if (tkxt->tkwin != Tk_Parent(oldWindow)) { - Tk_UnmaintainGeometry(oldWindow, tkxt->tkwin); - } else { - Tk_UnmapWindow(oldWindow); - } - } - if (ewPtr->body.ew.tkwin != NULL) { - Tk_Window ancestor, parent; - - /* - * Make sure that the text is either the parent of the - * embedded window or a descendant of that parent. Also, - * don't allow a top-level window to be managed inside - * a text. - */ - - parent = Tk_Parent(ewPtr->body.ew.tkwin); - for (ancestor = tkxt->tkwin; ; - ancestor = Tk_Parent(ancestor)) { - if (ancestor == parent) { - break; - } - if (Tk_IsTopLevel(ancestor)) { - badMaster: - Tcl_AppendResult(tkxt->interp, "can't embed ", - Tk_PathName(ewPtr->body.ew.tkwin), " in ", - Tk_PathName(tkxt->tkwin), (char *) NULL); - ewPtr->body.ew.tkwin = NULL; - return TCL_ERROR; - } - } - if (Tk_IsTopLevel(ewPtr->body.ew.tkwin) - || (ewPtr->body.ew.tkwin == tkxt->tkwin)) { - goto badMaster; - } - - /* - * Take over geometry management for the window, plus create - * an event handler to find out when it is deleted. - */ - - Tk_ManageGeometry(ewPtr->body.ew.tkwin, &textGeomType, - (gpointer) ewPtr); - Tk_CreateEventHandler(ewPtr->body.ew.tkwin, StructureNotifyMask, - EmbWinStructureFunc, (gpointer) ewPtr); - - /* - * Special trick! Must enter into the hash table *after* - * calling Tk_ManageGeometry: if the window was already managed - * elsewhere in this text, the Tk_ManageGeometry call will cause - * the entry to be removed, which could potentially lose the new - * entry. - */ - - hPtr = Tcl_CreateHashEntry(&tkxt->windowTable, - Tk_PathName(ewPtr->body.ew.tkwin), &new); - Tcl_SetHashValue(hPtr, ewPtr); - - } - } - return TCL_OK; -} - -/* - *-------------------------------------------------------------- - * - * AlignParseFunc -- - * - * This procedure is invoked by Tk_ConfigureWidget during - * option processing to handle "-align" options for embedded - * windows. - * - * Results: - * A standard Tcl return value. - * - * Side effects: - * The alignment for the embedded window may change. - * - *-------------------------------------------------------------- - */ - - /* ARGSUSED */ -static int -AlignParseFunc(clientData, interp, tkwin, value, widgRec, offset) - gpointer clientData; /* Not used.*/ - Tcl_Interp *interp; /* Used for reporting errors. */ - Tk_Window tkwin; /* Window for text widget. */ - char *value; /* Value of option. */ - char *widgRec; /* Pointer to GtkTextEmbWindow - * structure. */ - int offset; /* Offset into item (ignored). */ -{ - GtkTextEmbWindow *embPtr = (GtkTextEmbWindow *) widgRec; - - if (strcmp(value, "baseline") == 0) { - embPtr->align = ALIGN_BASELINE; - } else if (strcmp(value, "bottom") == 0) { - embPtr->align = ALIGN_BOTTOM; - } else if (strcmp(value, "center") == 0) { - embPtr->align = ALIGN_CENTER; - } else if (strcmp(value, "top") == 0) { - embPtr->align = ALIGN_TOP; - } else { - Tcl_AppendResult(interp, "bad alignment \"", value, - "\": must be baseline, bottom, center, or top", - (char *) NULL); - return TCL_ERROR; - } - return TCL_OK; -} - -/* - *-------------------------------------------------------------- - * - * AlignPrintFunc -- - * - * This procedure is invoked by the Tk configuration code - * to produce a printable string for the "-align" configuration - * option for embedded windows. - * - * Results: - * The return value is a string describing the embedded - * window's current alignment. - * - * Side effects: - * None. - * - *-------------------------------------------------------------- - */ - - /* ARGSUSED */ -static char * -AlignPrintFunc(clientData, tkwin, widgRec, offset, freeFuncPtr) - gpointer clientData; /* Ignored. */ - Tk_Window tkwin; /* Window for text widget. */ - char *widgRec; /* Pointer to GtkTextEmbWindow - * structure. */ - int offset; /* Ignored. */ - Tcl_FreeFunc **freeFuncPtr; /* Pointer to variable to fill in with - * information about how to reclaim - * storage for return string. */ -{ - switch (((GtkTextEmbWindow *) widgRec)->align) { - case ALIGN_BASELINE: - return "baseline"; - case ALIGN_BOTTOM: - return "bottom"; - case ALIGN_CENTER: - return "center"; - case ALIGN_TOP: - return "top"; - default: - return "??"; - } -} - -/* - *-------------------------------------------------------------- - * - * EmbWinStructureFunc -- - * - * This procedure is invoked by the Tk event loop whenever - * StructureNotify events occur for a window that's embedded - * in a text widget. This procedure's only purpose is to - * clean up when windows are deleted. - * - * Results: - * None. - * - * Side effects: - * The window is disassociated from the window segment, and - * the portion of the text is redisplayed. - * - *-------------------------------------------------------------- - */ - -static void -EmbWinStructureFunc(clientData, eventPtr) - gpointer clientData; /* Pointer to record describing window item. */ - XEvent *eventPtr; /* Describes what just happened. */ -{ - GtkTextLineSegment *ewPtr = (GtkTextLineSegment *) clientData; - GtkTextIndex index; - - if (eventPtr->type != DestroyNotify) { - return; - } - - Tcl_DeleteHashEntry(Tcl_FindHashEntry(&ewPtr->body.ew.tkxt->windowTable, - Tk_PathName(ewPtr->body.ew.tkwin))); - ewPtr->body.ew.tkwin = NULL; - index.tree = ewPtr->body.ew.tkxt->tree; - index.line = ewPtr->body.ew.line; - index.byteIndex = gtk_text_line_segment_get_offset(ewPtr, ewPtr->body.ew.line); - gtk_text_buffer_need_redisplay(ewPtr->body.ew.tkxt, &index, &index); -} - -/* - *-------------------------------------------------------------- - * - * EmbWinRequestFunc -- - * - * This procedure is invoked whenever a window that's associated - * with a window canvas item changes its requested dimensions. - * - * Results: - * None. - * - * Side effects: - * The size and location on the screen of the window may change, - * depending on the options specified for the window item. - * - *-------------------------------------------------------------- - */ - - /* ARGSUSED */ -static void -EmbWinRequestFunc(clientData, tkwin) - gpointer clientData; /* Pointer to record for window item. */ - Tk_Window tkwin; /* Window that changed its desired - * size. */ -{ - GtkTextLineSegment *ewPtr = (GtkTextLineSegment *) clientData; - GtkTextIndex index; - - index.tree = ewPtr->body.ew.tkxt->tree; - index.line = ewPtr->body.ew.line; - index.byteIndex = gtk_text_line_segment_get_offset(ewPtr, ewPtr->body.ew.line); - gtk_text_buffer_need_redisplay(ewPtr->body.ew.tkxt, &index, &index); -} - -/* - *-------------------------------------------------------------- - * - * EmbWinLostSlaveFunc -- - * - * This procedure is invoked by the Tk geometry manager when - * a slave window managed by a text widget is claimed away - * by another geometry manager. - * - * Results: - * None. - * - * Side effects: - * The window is disassociated from the window segment, and - * the portion of the text is redisplayed. - * - *-------------------------------------------------------------- - */ - -static void -EmbWinLostSlaveFunc(clientData, tkwin) - gpointer clientData; /* Pointer to record describing window item. */ - Tk_Window tkwin; /* Window that was claimed away by another - * geometry manager. */ -{ - GtkTextLineSegment *ewPtr = (GtkTextLineSegment *) clientData; - GtkTextIndex index; - - Tk_DeleteEventHandler(ewPtr->body.ew.tkwin, StructureNotifyMask, - EmbWinStructureFunc, (gpointer) ewPtr); - Tcl_CancelIdleCall(EmbWinDelayedUnmap, (gpointer) ewPtr); - if (ewPtr->body.ew.tkxt->tkwin != Tk_Parent(tkwin)) { - Tk_UnmaintainGeometry(tkwin, ewPtr->body.ew.tkxt->tkwin); - } else { - Tk_UnmapWindow(tkwin); - } - Tcl_DeleteHashEntry(Tcl_FindHashEntry(&ewPtr->body.ew.tkxt->windowTable, - Tk_PathName(ewPtr->body.ew.tkwin))); - ewPtr->body.ew.tkwin = NULL; - index.tree = ewPtr->body.ew.tkxt->tree; - index.line = ewPtr->body.ew.line; - index.byteIndex = gtk_text_line_segment_get_offset(ewPtr, ewPtr->body.ew.line); - gtk_text_buffer_need_redisplay(ewPtr->body.ew.tkxt, &index, &index); -} - -/* - *-------------------------------------------------------------- - * - * EmbWinDeleteFunc -- - * - * This procedure is invoked by the text B-tree code whenever - * an embedded window lies in a range of characters being deleted. - * - * Results: - * Returns 0 to indicate that the deletion has been accepted. - * - * Side effects: - * The embedded window is deleted, if it exists, and any resources - * associated with it are released. - * - *-------------------------------------------------------------- - */ - - /* ARGSUSED */ -static int -EmbWinDeleteFunc(ewPtr, line, treeGone) - GtkTextLineSegment *ewPtr; /* Segment being deleted. */ - GtkTextLine *line; /* Line containing segment. */ - int treeGone; /* Non-zero means the entire tree is - * being deleted, so everything must - * get cleaned up. */ -{ - Tcl_HashEntry *hPtr; - - if (ewPtr->body.ew.tkwin != NULL) { - hPtr = Tcl_FindHashEntry(&ewPtr->body.ew.tkxt->windowTable, - Tk_PathName(ewPtr->body.ew.tkwin)); - if (hPtr != NULL) { - /* - * (It's possible for there to be no hash table entry for this - * window, if an error occurred while creating the window segment - * but before the window got added to the table) - */ - - Tcl_DeleteHashEntry(hPtr); - } - - /* - * Delete the event handler for the window before destroying - * the window, so that EmbWinStructureFunc doesn't get called - * (we'll already do everything that it would have done, and - * it will just get confused). - */ - - Tk_DeleteEventHandler(ewPtr->body.ew.tkwin, StructureNotifyMask, - EmbWinStructureFunc, (gpointer) ewPtr); - Tk_DestroyWindow(ewPtr->body.ew.tkwin); - } - Tcl_CancelIdleCall(EmbWinDelayedUnmap, (gpointer) ewPtr); - Tk_FreeOptions(configSpecs, (char *) &ewPtr->body.ew, - ewPtr->body.ew.tkxt->display, 0); - g_free((char *) ewPtr); - return 0; -} - -/* - *-------------------------------------------------------------- - * - * EmbWinCleanupFunc -- - * - * This procedure is invoked by the B-tree code whenever a - * segment containing an embedded window is moved from one - * line to another. - * - * Results: - * None. - * - * Side effects: - * The line field of the segment gets updated. - * - *-------------------------------------------------------------- - */ - -static GtkTextLineSegment * -EmbWinCleanupFunc(ewPtr, line) - GtkTextLineSegment *ewPtr; /* Mark segment that's being moved. */ - GtkTextLine *line; /* Line that now contains segment. */ -{ - ewPtr->body.ew.line = line; - return ewPtr; -} - -/* - *-------------------------------------------------------------- - * - * EmbWinLayoutFunc -- - * - * This procedure is the "layoutFunc" for embedded window - * segments. - * - * Results: - * 1 is returned to indicate that the segment should be - * displayed. The chunkPtr structure is filled in. - * - * Side effects: - * None, except for filling in chunkPtr. - * - *-------------------------------------------------------------- - */ - - /*ARGSUSED*/ -static int -EmbWinLayoutFunc(tkxt, indexPtr, ewPtr, offset, maxX, maxChars, - noCharsYet, wrapMode, chunkPtr) - GtkTextView *tkxt; /* Text widget being layed out. */ - GtkTextIndex *indexPtr; /* Identifies first character in chunk. */ - GtkTextLineSegment *ewPtr; /* Segment corresponding to indexPtr. */ - int offset; /* Offset within segPtr corresponding to - * indexPtr (always 0). */ - int maxX; /* Chunk must not occupy pixels at this - * position or higher. */ - int maxChars; /* Chunk must not include more than this - * many characters. */ - int noCharsYet; /* Non-zero means no characters have been - * assigned to this line yet. */ - GtkWrapMode wrapMode; /* Wrap mode to use for line: GTK_WRAPMODE_CHAR, - * GTK_WRAPMODE_NONE, or GTK_WRAPMODE_WORD. */ - GtkTextDisplayChunk *chunkPtr; - /* Structure to fill in with information - * about this chunk. The x field has already - * been set by the caller. */ -{ - int width, height; - - if (offset != 0) { - panic("Non-zero offset in EmbWinLayoutFunc"); - } - - if ((ewPtr->body.ew.tkwin == NULL) && (ewPtr->body.ew.create != NULL)) { - int code, new; - Tcl_DString name; - Tk_Window ancestor; - Tcl_HashEntry *hPtr; - - /* - * The window doesn't currently exist. Create it by evaluating - * the creation script. The script must return the window's - * path name: look up that name to get back to the window - * token. Then ourselves as the geometry manager for - * the window. - */ - - code = Tcl_GlobalEval(tkxt->interp, ewPtr->body.ew.create); - if (code != TCL_OK) { - createError: - Tcl_BackgroundError(tkxt->interp); - goto gotWindow; - } - Tcl_DStringInit(&name); - Tcl_DStringAppend(&name, Tcl_GetStringResult(tkxt->interp), -1); - Tcl_ResetResult(tkxt->interp); - ewPtr->body.ew.tkwin = Tk_NameToWindow(tkxt->interp, - Tcl_DStringValue(&name), tkxt->tkwin); - if (ewPtr->body.ew.tkwin == NULL) { - goto createError; - } - for (ancestor = tkxt->tkwin; ; - ancestor = Tk_Parent(ancestor)) { - if (ancestor == Tk_Parent(ewPtr->body.ew.tkwin)) { - break; - } - if (Tk_IsTopLevel(ancestor)) { - badMaster: - Tcl_AppendResult(tkxt->interp, "can't embed ", - Tk_PathName(ewPtr->body.ew.tkwin), " relative to ", - Tk_PathName(tkxt->tkwin), (char *) NULL); - Tcl_BackgroundError(tkxt->interp); - ewPtr->body.ew.tkwin = NULL; - goto gotWindow; - } - } - if (Tk_IsTopLevel(ewPtr->body.ew.tkwin) - || (tkxt->tkwin == ewPtr->body.ew.tkwin)) { - goto badMaster; - } - Tk_ManageGeometry(ewPtr->body.ew.tkwin, &textGeomType, - (gpointer) ewPtr); - Tk_CreateEventHandler(ewPtr->body.ew.tkwin, StructureNotifyMask, - EmbWinStructureFunc, (gpointer) ewPtr); - - /* - * Special trick! Must enter into the hash table *after* - * calling Tk_ManageGeometry: if the window was already managed - * elsewhere in this text, the Tk_ManageGeometry call will cause - * the entry to be removed, which could potentially lose the new - * entry. - */ - - hPtr = Tcl_CreateHashEntry(&tkxt->windowTable, - Tk_PathName(ewPtr->body.ew.tkwin), &new); - Tcl_SetHashValue(hPtr, ewPtr); - } - - /* - * See if there's room for this window on this line. - */ - - gotWindow: - if (ewPtr->body.ew.tkwin == NULL) { - width = 0; - height = 0; - } else { - width = Tk_ReqWidth(ewPtr->body.ew.tkwin) + 2*ewPtr->body.ew.padX; - height = Tk_ReqHeight(ewPtr->body.ew.tkwin) + 2*ewPtr->body.ew.padY; - } - if ((width > (maxX - chunkPtr->x)) - && !noCharsYet && (tkxt->wrapMode != GTK_WRAPMODE_NONE)) { - return 0; - } - - /* - * Fill in the chunk structure. - */ - - chunkPtr->displayFunc = EmbWinDisplayFunc; - chunkPtr->undisplayFunc = EmbWinUndisplayFunc; - chunkPtr->measureFunc = (GtkTextViewChunkMeasureFunc *) NULL; - chunkPtr->bboxFunc = EmbWinBboxFunc; - chunkPtr->numBytes = 1; - if (ewPtr->body.ew.align == ALIGN_BASELINE) { - chunkPtr->minAscent = height - ewPtr->body.ew.padY; - chunkPtr->minDescent = ewPtr->body.ew.padY; - chunkPtr->minHeight = 0; - } else { - chunkPtr->minAscent = 0; - chunkPtr->minDescent = 0; - chunkPtr->minHeight = height; - } - chunkPtr->width = width; - chunkPtr->breakIndex = -1; - chunkPtr->breakIndex = 1; - chunkPtr->clientData = (gpointer) ewPtr; - ewPtr->body.ew.chunkCount += 1; - return 1; -} - -/* - *-------------------------------------------------------------- - * - * EmbWinCheckFunc -- - * - * This procedure is invoked by the B-tree code to perform - * consistency checks on embedded windows. - * - * Results: - * None. - * - * Side effects: - * The procedure panics if it detects anything wrong with - * the embedded window. - * - *-------------------------------------------------------------- - */ - -static void -EmbWinCheckFunc(ewPtr, line) - GtkTextLineSegment *ewPtr; /* Segment to check. */ - GtkTextLine *line; /* Line containing segment. */ -{ - if (ewPtr->next == NULL) { - panic("EmbWinCheckFunc: embedded window is last segment in line"); - } - if (ewPtr->size != 1) { - panic("EmbWinCheckFunc: embedded window has size %d", ewPtr->size); - } -} - -/* - *-------------------------------------------------------------- - * - * EmbWinDisplayFunc -- - * - * This procedure is invoked by the text displaying code - * when it is time to actually draw an embedded window - * chunk on the screen. - * - * Results: - * None. - * - * Side effects: - * The embedded window gets moved to the correct location - * and mapped onto the screen. - * - *-------------------------------------------------------------- - */ - -static void -EmbWinDisplayFunc(chunkPtr, x, y, lineHeight, baseline, display, dst, screenY) - GtkTextDisplayChunk *chunkPtr; /* Chunk that is to be drawn. */ - int x; /* X-position in dst at which to - * draw this chunk (differs from - * the x-position in the chunk because - * of scrolling). */ - int y; /* Top of rectangular bounding box - * for line: tells where to draw this - * chunk in dst (x-position is in - * the chunk itself). */ - int lineHeight; /* Total height of line. */ - int baseline; /* Offset of baseline from y. */ - Display *display; /* Display to use for drawing. */ - Drawable dst; /* Pixmap or window in which to draw */ - int screenY; /* Y-coordinate in text window that - * corresponds to y. */ -{ - GtkTextLineSegment *ewPtr = (GtkTextLineSegment *) chunkPtr->clientData; - int lineX, windowX, windowY, width, height; - Tk_Window tkwin; - - tkwin = ewPtr->body.ew.tkwin; - if (tkwin == NULL) { - return; - } - if ((x + chunkPtr->width) <= 0) { - /* - * The window is off-screen; just unmap it. - */ - - if (ewPtr->body.ew.tkxt->tkwin != Tk_Parent(tkwin)) { - Tk_UnmaintainGeometry(tkwin, ewPtr->body.ew.tkxt->tkwin); - } else { - Tk_UnmapWindow(tkwin); - } - return; - } - - /* - * Compute the window's location and size in the text widget, taking - * into account the align and stretch values for the window. - */ - - EmbWinBboxFunc(chunkPtr, 0, screenY, lineHeight, baseline, &lineX, - &windowY, &width, &height); - windowX = lineX - chunkPtr->x + x; - - if (ewPtr->body.ew.tkxt->tkwin == Tk_Parent(tkwin)) { - if ((windowX != Tk_X(tkwin)) || (windowY != Tk_Y(tkwin)) - || (Tk_ReqWidth(tkwin) != Tk_Width(tkwin)) - || (height != Tk_Height(tkwin))) { - Tk_MoveResizeWindow(tkwin, windowX, windowY, width, height); - } - Tk_MapWindow(tkwin); - } else { - Tk_MaintainGeometry(tkwin, ewPtr->body.ew.tkxt->tkwin, - windowX, windowY, width, height); - } - - /* - * Mark the window as displayed so that it won't get unmapped. - */ - - ewPtr->body.ew.displayed = 1; -} - -/* - *-------------------------------------------------------------- - * - * EmbWinUndisplayFunc -- - * - * This procedure is called when the chunk for an embedded - * window is no longer going to be displayed. It arranges - * for the window associated with the chunk to be unmapped. - * - * Results: - * None. - * - * Side effects: - * The window is scheduled for unmapping. - * - *-------------------------------------------------------------- - */ - -static void -EmbWinUndisplayFunc(tkxt, chunkPtr) - GtkTextView *tkxt; /* Overall information about text - * widget. */ - GtkTextDisplayChunk *chunkPtr; /* Chunk that is about to be freed. */ -{ - GtkTextLineSegment *ewPtr = (GtkTextLineSegment *) chunkPtr->clientData; - - ewPtr->body.ew.chunkCount--; - if (ewPtr->body.ew.chunkCount == 0) { - /* - * Don't unmap the window immediately, since there's a good chance - * that it will immediately be redisplayed, perhaps even in the - * same place. Instead, schedule the window to be unmapped later; - * the call to EmbWinDelayedUnmap will be cancelled in the likely - * event that the unmap becomes unnecessary. - */ - - ewPtr->body.ew.displayed = 0; - Tcl_DoWhenIdle(EmbWinDelayedUnmap, (gpointer) ewPtr); - } -} - -/* - *-------------------------------------------------------------- - * - * EmbWinBboxFunc -- - * - * This procedure is called to compute the bounding box of - * the area occupied by an embedded window. - * - * Results: - * There is no return value. *xPtr and *yPtr are filled in - * with the coordinates of the upper left corner of the - * window, and *widthPtr and *heightPtr are filled in with - * the dimensions of the window in pixels. Note: not all - * of the returned bbox is necessarily visible on the screen - * (the rightmost part might be off-screen to the right, - * and the bottommost part might be off-screen to the bottom). - * - * Side effects: - * None. - * - *-------------------------------------------------------------- - */ - -static void -EmbWinBboxFunc(chunkPtr, index, y, lineHeight, baseline, xPtr, yPtr, - widthPtr, heightPtr) - GtkTextDisplayChunk *chunkPtr; /* Chunk containing desired char. */ - int index; /* Index of desired character within - * the chunk. */ - int y; /* Topmost pixel in area allocated - * for this line. */ - int lineHeight; /* Total height of line. */ - int baseline; /* Location of line's baseline, in - * pixels measured down from y. */ - int *xPtr, *yPtr; /* Gets filled in with coords of - * character's upper-left pixel. */ - int *widthPtr; /* Gets filled in with width of - * character, in pixels. */ - int *heightPtr; /* Gets filled in with height of - * character, in pixels. */ -{ - GtkTextLineSegment *ewPtr = (GtkTextLineSegment *) chunkPtr->clientData; - Tk_Window tkwin; - - tkwin = ewPtr->body.ew.tkwin; - if (tkwin != NULL) { - *widthPtr = Tk_ReqWidth(tkwin); - *heightPtr = Tk_ReqHeight(tkwin); - } else { - *widthPtr = 0; - *heightPtr = 0; - } - *xPtr = chunkPtr->x + ewPtr->body.ew.padX; - if (ewPtr->body.ew.stretch) { - if (ewPtr->body.ew.align == ALIGN_BASELINE) { - *heightPtr = baseline - ewPtr->body.ew.padY; - } else { - *heightPtr = lineHeight - 2*ewPtr->body.ew.padY; - } - } - switch (ewPtr->body.ew.align) { - case ALIGN_BOTTOM: - *yPtr = y + (lineHeight - *heightPtr - ewPtr->body.ew.padY); - break; - case ALIGN_CENTER: - *yPtr = y + (lineHeight - *heightPtr)/2; - break; - case ALIGN_TOP: - *yPtr = y + ewPtr->body.ew.padY; - break; - case ALIGN_BASELINE: - *yPtr = y + (baseline - *heightPtr); - break; - } -} - -/* - *-------------------------------------------------------------- - * - * EmbWinDelayedUnmap -- - * - * This procedure is an idle handler that does the actual - * work of unmapping an embedded window. See the comment - * in EmbWinUndisplayFunc for details. - * - * Results: - * None. - * - * Side effects: - * The window gets unmapped, unless its chunk reference count - * has become non-zero again. - * - *-------------------------------------------------------------- - */ - -static void -EmbWinDelayedUnmap(clientData) - gpointer clientData; /* Token for the window to - * be unmapped. */ -{ - GtkTextLineSegment *ewPtr = (GtkTextLineSegment *) clientData; - - if (!ewPtr->body.ew.displayed && (ewPtr->body.ew.tkwin != NULL)) { - if (ewPtr->body.ew.tkxt->tkwin != Tk_Parent(ewPtr->body.ew.tkwin)) { - Tk_UnmaintainGeometry(ewPtr->body.ew.tkwin, - ewPtr->body.ew.tkxt->tkwin); - } else { - Tk_UnmapWindow(ewPtr->body.ew.tkwin); - } - } -} - -/* - *-------------------------------------------------------------- - * - * GtkTextViewWindowIndex -- - * - * Given the name of an embedded window within a text widget, - * returns an index corresponding to the window's position - * in the text. - * - * Results: - * The return value is 1 if there is an embedded window by - * the given name in the text widget, 0 otherwise. If the - * window exists, *indexPtr is filled in with its index. - * - * Side effects: - * None. - * - *-------------------------------------------------------------- - */ - -int -GtkTextViewWindowIndex(tkxt, name, indexPtr) - GtkTextView *tkxt; /* Text widget containing window. */ - char *name; /* Name of window. */ - GtkTextIndex *indexPtr; /* Index information gets stored here. */ -{ - Tcl_HashEntry *hPtr; - GtkTextLineSegment *ewPtr; - - hPtr = Tcl_FindHashEntry(&tkxt->windowTable, name); - if (hPtr == NULL) { - return 0; - } - ewPtr = (GtkTextLineSegment *) Tcl_GetHashValue(hPtr); - indexPtr->tree = tkxt->tree; - indexPtr->line = ewPtr->body.ew.line; - indexPtr->byteIndex = gtk_text_line_segment_get_offset(ewPtr, indexPtr->line); - return 1; -} -#endif diff --git a/gtk/gtktextchild.h b/gtk/gtktextchild.h index 3344a5a8d4..6ea7075f60 100644 --- a/gtk/gtktextchild.h +++ b/gtk/gtktextchild.h @@ -7,14 +7,13 @@ extern "C" { #endif /* __cplusplus */ -typedef struct _GtkTextPixmap GtkTextPixmap; +typedef struct _GtkTextPixbuf GtkTextPixbuf; -struct _GtkTextPixmap { - GdkPixmap *pixmap; - GdkBitmap *mask; +struct _GtkTextPixbuf { + GdkPixbuf *pixbuf; }; -GtkTextLineSegment *gtk_text_pixmap_segment_new(GdkPixmap *pixmap, GdkBitmap *mask); +GtkTextLineSegment *gtk_text_pixbuf_segment_new(GdkPixbuf *pixbuf); #ifdef __cplusplus diff --git a/gtk/gtktextdisplay.c b/gtk/gtktextdisplay.c index 54e7d189dd..d5cd2ed336 100644 --- a/gtk/gtktextdisplay.c +++ b/gtk/gtktextdisplay.c @@ -159,7 +159,7 @@ static void render_layout_line (GdkDrawable *drawable, GtkTextRenderState *render_state, PangoLayoutLine *line, - GSList **pixmap_pointer, + GSList **pixbuf_pointer, int x, int y, gboolean selected) @@ -246,37 +246,67 @@ render_layout_line (GdkDrawable *drawable, x_off += logical_rect.width; } - else /* Pixmap segment */ + else /* Pixbuf segment */ { - GtkTextPixmap *pixmap = (*pixmap_pointer)->data; + GtkTextPixbuf *pixbuf = (*pixbuf_pointer)->data; gint width, height; - GdkRectangle pixmap_rect, draw_rect; - - *pixmap_pointer = (*pixmap_pointer)->next; - - gdk_drawable_get_size (pixmap->pixmap, &width, &height); - - pixmap_rect.x = x + x_off / PANGO_SCALE; - pixmap_rect.y = y - height; - pixmap_rect.width = width; - pixmap_rect.height = height; - - gdk_rectangle_intersect (&pixmap_rect, &render_state->clip_rect, &draw_rect); - - if (pixmap->mask) - { - gdk_gc_set_clip_mask (render_state->fg_gc, pixmap->mask); - gdk_gc_set_clip_origin (render_state->fg_gc, - pixmap_rect.x, pixmap_rect.y); - } - - gdk_draw_drawable (drawable, render_state->fg_gc, pixmap->pixmap, - draw_rect.x - pixmap_rect.x, draw_rect.y - pixmap_rect.y, - draw_rect.x, draw_rect.y, draw_rect.width, draw_rect.height); - - if (pixmap->mask) - gdk_gc_set_clip_rectangle (render_state->fg_gc, &render_state->clip_rect); - + GdkRectangle pixbuf_rect, draw_rect; + GdkBitmap *mask = NULL; + + *pixbuf_pointer = (*pixbuf_pointer)->next; + + width = gdk_pixbuf_get_width (pixbuf->pixbuf); + height = gdk_pixbuf_get_height (pixbuf->pixbuf); + + pixbuf_rect.x = x + x_off / PANGO_SCALE; + pixbuf_rect.y = y - height; + pixbuf_rect.width = width; + pixbuf_rect.height = height; + + if (gdk_rectangle_intersect (&pixbuf_rect, &render_state->clip_rect, + &draw_rect)) + { + if (gdk_pixbuf_get_has_alpha (pixbuf->pixbuf)) + { + mask = gdk_pixmap_new (drawable, + gdk_pixbuf_get_width (pixbuf->pixbuf), + gdk_pixbuf_get_height (pixbuf->pixbuf), + 1); + + gdk_pixbuf_render_threshold_alpha (pixbuf->pixbuf, mask, + 0, 0, 0, 0, + gdk_pixbuf_get_width (pixbuf->pixbuf), + gdk_pixbuf_get_height (pixbuf->pixbuf), + 128); + + } + + if (mask) + { + gdk_gc_set_clip_mask (render_state->fg_gc, mask); + gdk_gc_set_clip_origin (render_state->fg_gc, + pixbuf_rect.x, pixbuf_rect.y); + } + + gdk_pixbuf_render_to_drawable (pixbuf->pixbuf, + drawable, + render_state->fg_gc, + draw_rect.x - pixbuf_rect.x, + draw_rect.y - pixbuf_rect.y, + draw_rect.x, draw_rect.y, + draw_rect.width, + draw_rect.height, + GDK_RGB_DITHER_NORMAL, + 0, 0); + + if (mask) + { + gdk_gc_set_clip_rectangle (render_state->fg_gc, + &render_state->clip_rect); + g_object_unref (G_OBJECT (mask)); + } + } + x_off += width * PANGO_SCALE; } } @@ -292,7 +322,7 @@ render_para (GdkDrawable *drawable, int selection_end_index) { PangoRectangle logical_rect; - GSList *pixmap_pointer = line_display->pixmaps; + GSList *pixbuf_pointer = line_display->pixbufs; GSList *tmp_list; PangoAlignment align; PangoLayout *layout = line_display->layout; @@ -375,15 +405,15 @@ render_para (GdkDrawable *drawable, TRUE, x + line_display->left_margin, selection_y, total_width / PANGO_SCALE, selection_height); - render_layout_line (drawable, render_state, line, &pixmap_pointer, + render_layout_line (drawable, render_state, line, &pixbuf_pointer, x + x_offset / PANGO_SCALE, y + (y_offset - logical_rect.y) / PANGO_SCALE, TRUE); } else { - GSList *pixmap_pointer_tmp = pixmap_pointer; + GSList *pixbuf_pointer_tmp = pixbuf_pointer; - render_layout_line (drawable, render_state, line, &pixmap_pointer, + render_layout_line (drawable, render_state, line, &pixbuf_pointer, x + x_offset / PANGO_SCALE, y + (y_offset - logical_rect.y) / PANGO_SCALE, FALSE); @@ -405,7 +435,7 @@ render_para (GdkDrawable *drawable, logical_rect.width / PANGO_SCALE, selection_height); - render_layout_line (drawable, render_state, line, &pixmap_pointer_tmp, + render_layout_line (drawable, render_state, line, &pixbuf_pointer_tmp, x + x_offset / PANGO_SCALE, y + (y_offset - logical_rect.y) / PANGO_SCALE, TRUE); diff --git a/gtk/gtktextiter.c b/gtk/gtktextiter.c index a0d5af31c4..cad7b9cf5a 100644 --- a/gtk/gtktextiter.c +++ b/gtk/gtktextiter.c @@ -794,34 +794,21 @@ gtk_text_iter_get_visible_text (const GtkTextIter *start, } /** - * gtk_text_iter_get_pixmap: + * gtk_text_iter_get_pixbuf: * @iter: an iterator - * @pixmap: return location for the pixmap - * @mask: return location for the mask - * - * If the location pointed to by @iter contains a pixmap, the pixmap - * is placed in @pixmap, the mask is placed in @mask, and - * gtk_text_iter_get_pixmap() returns TRUE. If @iter points at - * something else, FALSE will be returned and @pixmap/@mask will - * remain unchanged. The pixmap and mask do not have their reference - * count incremented. If the pixmap has no mask, NULL is returned for - * the mask. - * - * Return value: whether the iterator pointed at a pixmap + * + * If the location pointed to by @iter contains a pixbuf, the pixbuf + * is returned (with no new reference count added). Otherwise, + * NULL is returned. + * + * Return value: the pixbuf at @iter **/ -gboolean -gtk_text_iter_get_pixmap (const GtkTextIter *iter, - GdkPixmap** pixmap, - GdkBitmap** mask) +GdkPixbuf* +gtk_text_iter_get_pixbuf (const GtkTextIter *iter) { GtkTextRealIter *real; g_return_val_if_fail(iter != NULL, FALSE); - g_return_val_if_fail(pixmap != NULL, FALSE); - g_return_val_if_fail(mask != NULL, FALSE); - - *pixmap = NULL; - *mask = NULL; real = gtk_text_iter_make_real(iter); @@ -830,17 +817,10 @@ gtk_text_iter_get_pixmap (const GtkTextIter *iter, check_invariants(iter); - if (real->segment->type != >k_text_pixmap_type) + if (real->segment->type != >k_text_pixbuf_type) return FALSE; else - { - if (pixmap) - *pixmap = real->segment->body.pixmap.pixmap; - if (mask) - *mask = real->segment->body.pixmap.pixmap; - - return TRUE; - } + return real->segment->body.pixbuf.pixbuf; } /** diff --git a/gtk/gtktextiter.h b/gtk/gtktextiter.h index e11272e19b..740533fcbe 100644 --- a/gtk/gtktextiter.h +++ b/gtk/gtktextiter.h @@ -72,12 +72,8 @@ gchar *gtk_text_iter_get_visible_slice (const GtkTextIter *start, gchar *gtk_text_iter_get_visible_text (const GtkTextIter *start, const GtkTextIter *end); -/* Returns TRUE if the iterator pointed at a pixmap */ -gboolean gtk_text_iter_get_pixmap (const GtkTextIter *iter, - GdkPixmap **pixmap, - GdkBitmap **mask); - -GSList *gtk_text_iter_get_marks (const GtkTextIter *iter); +GdkPixbuf* gtk_text_iter_get_pixbuf (const GtkTextIter *iter); +GSList * gtk_text_iter_get_marks (const GtkTextIter *iter); /* Return list of tags toggled at this point (toggled_on determines whether the list is of on-toggles or off-toggles) */ diff --git a/gtk/gtktextlayout.c b/gtk/gtktextlayout.c index 730b4fde46..5ef74c0017 100644 --- a/gtk/gtktextlayout.c +++ b/gtk/gtktextlayout.c @@ -1170,7 +1170,7 @@ add_text_attrs (GtkTextLayout *layout, } static void -add_pixmap_attrs (GtkTextLayout *layout, +add_pixbuf_attrs (GtkTextLayout *layout, GtkTextLineDisplay *display, GtkTextAttributes *style, GtkTextLineSegment *seg, @@ -1179,10 +1179,12 @@ add_pixmap_attrs (GtkTextLayout *layout, { PangoAttribute *attr; PangoRectangle logical_rect; - GtkTextPixmap *pixmap = &seg->body.pixmap; + GtkTextPixbuf *pixbuf = &seg->body.pixbuf; gint width, height; - gdk_drawable_get_size (pixmap->pixmap, &width, &height); + width = gdk_pixbuf_get_width (pixbuf->pixbuf); + height = gdk_pixbuf_get_height (pixbuf->pixbuf); + logical_rect.x = 0; logical_rect.y = -height * PANGO_SCALE; logical_rect.width = width * PANGO_SCALE; @@ -1193,7 +1195,7 @@ add_pixmap_attrs (GtkTextLayout *layout, attr->end_index = start + seg->byte_count; pango_attr_list_insert (attrs, attr); - display->pixmaps = g_slist_append (display->pixmaps, pixmap); + display->pixbufs = g_slist_append (display->pixbufs, pixbuf); } static void @@ -1305,7 +1307,7 @@ gtk_text_layout_get_line_display (GtkTextLayout *layout, { /* Displayable segments */ if (seg->type == >k_text_char_type || - seg->type == >k_text_pixmap_type) + seg->type == >k_text_pixbuf_type) { gtk_text_btree_get_iter_at_line (_gtk_text_buffer_get_btree (layout->buffer), &iter, line, @@ -1313,7 +1315,7 @@ gtk_text_layout_get_line_display (GtkTextLayout *layout, style = get_style (layout, &iter); /* We have to delay setting the paragraph values until we - * hit the first pixmap or text segment because toggles at + * hit the first pixbuf or text segment because toggles at * the beginning of the paragraph should affect the * paragraph-global values */ @@ -1367,7 +1369,7 @@ gtk_text_layout_get_line_display (GtkTextLayout *layout, } else { - add_pixmap_attrs (layout, display, style, seg, attrs, byte_offset); + add_pixbuf_attrs (layout, display, style, seg, attrs, byte_offset); memcpy (text + byte_offset, gtk_text_unknown_char_utf8, seg->byte_count); byte_offset += seg->byte_count; } @@ -1461,7 +1463,7 @@ gtk_text_layout_free_line_display (GtkTextLayout *layout, { g_slist_foreach (display->cursors, (GFunc)g_free, NULL); g_slist_free (display->cursors); - g_slist_free (display->pixmaps); + g_slist_free (display->pixbufs); } g_free (display); diff --git a/gtk/gtktextlayout.h b/gtk/gtktextlayout.h index 79b569f61a..5d812f1a99 100644 --- a/gtk/gtktextlayout.h +++ b/gtk/gtktextlayout.h @@ -132,7 +132,7 @@ struct _GtkTextLineDisplay { PangoLayout *layout; GSList *cursors; - GSList *pixmaps; + GSList *pixbufs; GtkTextDirection direction; @@ -146,7 +146,7 @@ struct _GtkTextLineDisplay gint bottom_margin; gboolean size_only; - GtkTextLine *line; + GtkTextLine *line; }; extern PangoAttrType gtk_text_attr_appearance_type; diff --git a/gtk/gtktextmark.c b/gtk/gtktextmark.c index f85ef0a6ba..4a53161ed2 100644 --- a/gtk/gtktextmark.c +++ b/gtk/gtktextmark.c @@ -25,14 +25,14 @@ gtk_text_mark_is_visible(GtkTextMark *mark) return seg->body.mark.visible; } -char * +const char * gtk_text_mark_get_name (GtkTextMark *mark) { GtkTextLineSegment *seg; seg = (GtkTextLineSegment*)mark; - return g_strdup (seg->body.mark.name); + return seg->body.mark.name; } diff --git a/gtk/gtktextmark.h b/gtk/gtktextmark.h index 19cb7a8df0..feab32378d 100644 --- a/gtk/gtktextmark.h +++ b/gtk/gtktextmark.h @@ -9,17 +9,15 @@ extern "C" { typedef struct _GtkTextMark GtkTextMark; -void gtk_text_mark_set_visible (GtkTextMark *mark, - gboolean setting); +void gtk_text_mark_set_visible (GtkTextMark *mark, + gboolean setting); +gboolean gtk_text_mark_is_visible (GtkTextMark *mark); +/* FIXME gconst */ +const char * gtk_text_mark_get_name (GtkTextMark *mark); +GtkTextMark *gtk_text_mark_ref (GtkTextMark *mark); +void gtk_text_mark_unref (GtkTextMark *mark); +gboolean gtk_text_mark_deleted (GtkTextMark *mark); -gboolean gtk_text_mark_is_visible (GtkTextMark *mark); -/* Temporarily commented out until memory management behavior is figured out */ -/* char * gtk_text_mark_get_name (GtkTextMark *mark); */ - -GtkTextMark *gtk_text_mark_ref (GtkTextMark *mark); -void gtk_text_mark_unref (GtkTextMark *mark); - -gboolean gtk_text_mark_deleted (GtkTextMark *mark); #ifdef __cplusplus } diff --git a/gtk/gtktextsegment.h b/gtk/gtktextsegment.h index 4d2d99a784..844663d437 100644 --- a/gtk/gtktextsegment.h +++ b/gtk/gtktextsegment.h @@ -102,7 +102,7 @@ struct _GtkTextLineSegment { * hold as many characters as needed.*/ GtkTextToggleBody toggle; /* Information about tag toggle. */ GtkTextMarkBody mark; /* Information about mark. */ - GtkTextPixmap pixmap; /* Child pixmap */ + GtkTextPixbuf pixbuf; /* Child pixbuf */ #if 0 GtkTextChild child; /* child widget */ #endif diff --git a/gtk/gtktexttag.c b/gtk/gtktexttag.c index 2c13409c26..54d91d0bf2 100644 --- a/gtk/gtktexttag.c +++ b/gtk/gtktexttag.c @@ -945,43 +945,47 @@ delta_priority_foreach(GtkTextTag *tag, gpointer user_data) gint gtk_text_tag_get_priority (GtkTextTag *tag) { - g_return_val_if_fail(GTK_IS_TEXT_TAG(tag), 0); + g_return_val_if_fail (GTK_IS_TEXT_TAG(tag), 0); return tag->priority; } void -gtk_text_tag_set_priority(GtkTextTag *tag, - gint priority) +gtk_text_tag_set_priority (GtkTextTag *tag, + gint priority) { DeltaData dd; - g_return_if_fail(GTK_IS_TEXT_TAG(tag)); - g_return_if_fail(tag->table != NULL); - g_return_if_fail(priority >= 0); - g_return_if_fail(priority < gtk_text_tag_table_size(tag->table)); + g_return_if_fail (GTK_IS_TEXT_TAG (tag)); + g_return_if_fail (tag->table != NULL); + g_return_if_fail (priority >= 0); + g_return_if_fail (priority < gtk_text_tag_table_size (tag->table)); if (priority == tag->priority) return; - if (priority < tag->priority) { - dd.low = priority; - dd.high = tag->priority - 1; - dd.delta = 1; - } else { - dd.low = tag->priority + 1; - dd.high = priority; - dd.delta = -1; - } + if (priority < tag->priority) + { + dd.low = priority; + dd.high = tag->priority - 1; + dd.delta = 1; + } + else + { + dd.low = tag->priority + 1; + dd.high = priority; + dd.delta = -1; + } - gtk_text_tag_table_foreach(tag->table, delta_priority_foreach, - &dd); + gtk_text_tag_table_foreach (tag->table, + delta_priority_foreach, + &dd); tag->priority = priority; } gint -gtk_text_tag_event(GtkTextTag *tag, +gtk_text_tag_event (GtkTextTag *tag, GtkObject *event_object, GdkEvent *event, const GtkTextIter *iter) @@ -992,12 +996,12 @@ gtk_text_tag_event(GtkTextTag *tag, g_return_val_if_fail(GTK_IS_OBJECT(event_object), FALSE); g_return_val_if_fail(event != NULL, FALSE); - gtk_signal_emit(GTK_OBJECT(tag), - signals[EVENT], - event_object, - event, - iter, - &retval); + gtk_signal_emit (GTK_OBJECT(tag), + signals[EVENT], + event_object, + event, + iter, + &retval); return retval; } diff --git a/gtk/gtktexttypes.h b/gtk/gtktexttypes.h index 85aeb7f850..8c7b34259b 100644 --- a/gtk/gtktexttypes.h +++ b/gtk/gtktexttypes.h @@ -31,7 +31,7 @@ extern GtkTextLineSegmentClass gtk_text_left_mark_type; extern GtkTextLineSegmentClass gtk_text_right_mark_type; /* In gtktextchild.c */ -extern GtkTextLineSegmentClass gtk_text_pixmap_type; +extern GtkTextLineSegmentClass gtk_text_pixbuf_type; extern GtkTextLineSegmentClass gtk_text_view_child_type; /* diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c index aedba9469e..3e198bed67 100644 --- a/gtk/gtktextview.c +++ b/gtk/gtktextview.c @@ -63,6 +63,7 @@ #include #define FOCUS_EDGE_WIDTH 25 +#define DRAG_THRESHOLD 8 #define SCREEN_WIDTH(widget) text_window_get_width (GTK_TEXT_VIEW (widget)->text_window) #define SCREEN_HEIGHT(widget) text_window_get_height (GTK_TEXT_VIEW (widget)->text_window) @@ -202,12 +203,12 @@ static void gtk_text_view_ensure_layout (GtkTextView *text_vi static void gtk_text_view_destroy_layout (GtkTextView *text_view); static void gtk_text_view_start_selection_drag (GtkTextView *text_view, const GtkTextIter *iter, - GdkEventButton *event); + GdkEventButton *event); static gboolean gtk_text_view_end_selection_drag (GtkTextView *text_view, GdkEventButton *event); static void gtk_text_view_start_selection_dnd (GtkTextView *text_view, const GtkTextIter *iter, - GdkEventButton *event); + GdkEventMotion *event); static void gtk_text_view_start_cursor_blink (GtkTextView *text_view); static void gtk_text_view_stop_cursor_blink (GtkTextView *text_view); @@ -219,7 +220,7 @@ static void gtk_text_view_commit_handler (GtkIMContext *context, static void gtk_text_view_mark_set_handler (GtkTextBuffer *buffer, const GtkTextIter *location, - const char *mark_name, + GtkTextMark *mark, gpointer data); static void gtk_text_view_get_virtual_cursor_pos (GtkTextView *text_view, gint *x, @@ -664,6 +665,9 @@ gtk_text_view_init (GtkTextView *text_view) text_view->text_window = text_window_new (GTK_TEXT_WINDOW_TEXT, widget, 200, 200); + + text_view->drag_start_x = -1; + text_view->drag_start_y = -1; } GtkWidget* @@ -730,7 +734,7 @@ gtk_text_view_set_buffer (GtkTextView *text_view, gtk_text_view_mark_set_handler, text_view); } - if (GTK_WIDGET_VISIBLE (text_view)) + if (GTK_WIDGET_VISIBLE (text_view)) gtk_widget_queue_draw (GTK_WIDGET (text_view)); } @@ -768,6 +772,35 @@ gtk_text_view_get_iter_location (GtkTextView *text_view, gtk_text_layout_get_iter_location (text_view->layout, iter, location); } +void +gtk_text_view_get_line_yrange (GtkTextView *text_view, + const GtkTextIter *iter, + gint *y, + gint *height) +{ + g_return_if_fail (GTK_IS_TEXT_VIEW (text_view)); + g_return_if_fail (gtk_text_iter_get_buffer (iter) == text_view->buffer); + + gtk_text_layout_get_line_yrange (text_view->layout, + iter, + y, + height); +} + +void +gtk_text_view_get_line_at_y (GtkTextView *text_view, + GtkTextIter *target_iter, + gint y, + gint *line_top) +{ + g_return_if_fail (GTK_IS_TEXT_VIEW (text_view)); + + gtk_text_layout_get_line_at_y (text_view->layout, + target_iter, + y, + line_top); +} + static void set_adjustment_clamped (GtkAdjustment *adj, gfloat val) { @@ -1842,7 +1875,8 @@ gtk_text_view_button_press_event (GtkWidget *widget, GdkEventButton *event) if (event->button == 1) { /* If we're in the selection, start a drag copy/move of the - selection; otherwise, start creating a new selection. */ + * selection; otherwise, start creating a new selection. + */ GtkTextIter iter; GtkTextIter start, end; @@ -1855,7 +1889,8 @@ gtk_text_view_button_press_event (GtkWidget *widget, GdkEventButton *event) &start, &end) && gtk_text_iter_in_region (&iter, &start, &end)) { - gtk_text_view_start_selection_dnd (text_view, &iter, event); + text_view->drag_start_x = event->x; + text_view->drag_start_y = event->y; } else { @@ -1902,8 +1937,22 @@ gtk_text_view_button_release_event (GtkWidget *widget, GdkEventButton *event) if (event->button == 1) { - gtk_text_view_end_selection_drag (GTK_TEXT_VIEW (widget), event); - return TRUE; + if (text_view->drag_start_x >= 0) + { + text_view->drag_start_x = -1; + text_view->drag_start_y = -1; + } + + if (gtk_text_view_end_selection_drag (GTK_TEXT_VIEW (widget), event)) + return TRUE; + else + { + /* Unselect everything; probably we were dragging, or clicked + * outside the text. + */ + gtk_text_view_unselect (text_view); + return FALSE; + } } return FALSE; @@ -1950,6 +1999,41 @@ gtk_text_view_focus_out_event (GtkWidget *widget, GdkEventFocus *event) static gint gtk_text_view_motion_event (GtkWidget *widget, GdkEventMotion *event) { + GtkTextView *text_view = GTK_TEXT_VIEW (widget); + + if (event->window == text_view->text_window->bin_window && + text_view->drag_start_x >= 0) + { + gint x, y; + gint dx, dy; + + gdk_window_get_pointer (text_view->text_window->bin_window, + &x, &y, NULL); + + dx = text_view->drag_start_x - x; + dy = text_view->drag_start_y - y; + + if (ABS (dx) > DRAG_THRESHOLD || + ABS (dy) > DRAG_THRESHOLD) + { + GtkTextIter iter; + gint buffer_x, buffer_y; + + gtk_text_view_window_to_buffer_coords (text_view, + GTK_TEXT_WINDOW_TEXT, + text_view->drag_start_x, + text_view->drag_start_y, + &buffer_x, + &buffer_y); + + gtk_text_layout_get_iter_at_pixel (text_view->layout, + &iter, + buffer_x, buffer_y); + + gtk_text_view_start_selection_dnd (text_view, &iter, event); + return TRUE; + } + } return FALSE; } @@ -2645,9 +2729,9 @@ selection_motion_event_handler (GtkTextView *text_view, GdkEventMotion *event, g } static void -gtk_text_view_start_selection_drag (GtkTextView *text_view, +gtk_text_view_start_selection_drag (GtkTextView *text_view, const GtkTextIter *iter, - GdkEventButton *event) + GdkEventButton *button) { GtkTextIter newplace; @@ -2876,11 +2960,14 @@ gtk_text_view_destroy_layout (GtkTextView *text_view) static void gtk_text_view_start_selection_dnd (GtkTextView *text_view, - const GtkTextIter *iter, - GdkEventButton *event) + const GtkTextIter *iter, + GdkEventMotion *event) { GdkDragContext *context; GtkTargetList *target_list; + + text_view->drag_start_x = -1; + text_view->drag_start_y = -1; target_list = gtk_target_list_new (target_table, G_N_ELEMENTS (target_table)); @@ -2953,6 +3040,10 @@ static void gtk_text_view_drag_data_delete (GtkWidget *widget, GdkDragContext *context) { + GtkTextView *text_view; + + text_view = GTK_TEXT_VIEW (widget); + gtk_text_buffer_delete_selection (GTK_TEXT_VIEW (widget)->buffer, TRUE, GTK_TEXT_VIEW (widget)->editable); } @@ -3277,12 +3368,12 @@ gtk_text_view_commit_handler (GtkIMContext *context, static void gtk_text_view_mark_set_handler (GtkTextBuffer *buffer, const GtkTextIter *location, - const char *mark_name, + GtkTextMark *mark, gpointer data) { GtkTextView *text_view = GTK_TEXT_VIEW (data); - - if (!strcmp (mark_name, "insert")) + + if (mark == gtk_text_buffer_get_insert (buffer)) { text_view->virtual_cursor_x = -1; text_view->virtual_cursor_y = -1; @@ -3918,45 +4009,64 @@ set_window_height (GtkTextView *text_view, } void -gtk_text_view_set_left_window_width (GtkTextView *text_view, - gint width) -{ - g_return_if_fail (GTK_IS_TEXT_VIEW (text_view)); - g_return_if_fail (width >= 0); - - set_window_width (text_view, width, GTK_TEXT_WINDOW_LEFT, - &text_view->left_window); -} +gtk_text_view_set_border_window_size (GtkTextView *text_view, + GtkTextWindowType type, + gint size) -void -gtk_text_view_set_right_window_width (GtkTextView *text_view, - gint width) { g_return_if_fail (GTK_IS_TEXT_VIEW (text_view)); - g_return_if_fail (width >= 0); + g_return_if_fail (size >= 0); + g_return_if_fail (type != GTK_TEXT_WINDOW_WIDGET); + g_return_if_fail (type != GTK_TEXT_WINDOW_TEXT); + + switch (type) + { + case GTK_TEXT_WINDOW_LEFT: + set_window_width (text_view, size, GTK_TEXT_WINDOW_LEFT, + &text_view->left_window); + break; - set_window_width (text_view, width, GTK_TEXT_WINDOW_RIGHT, - &text_view->right_window); -} + case GTK_TEXT_WINDOW_RIGHT: + set_window_width (text_view, size, GTK_TEXT_WINDOW_RIGHT, + &text_view->right_window); + break; -void -gtk_text_view_set_top_window_height (GtkTextView *text_view, - gint height) -{ - g_return_if_fail (GTK_IS_TEXT_VIEW (text_view)); - g_return_if_fail (height >= 0); + case GTK_TEXT_WINDOW_TOP: + set_window_height (text_view, size, GTK_TEXT_WINDOW_TOP, + &text_view->top_window); + break; - set_window_height (text_view, height, GTK_TEXT_WINDOW_TOP, - &text_view->top_window); + case GTK_TEXT_WINDOW_BOTTOM: + set_window_height (text_view, size, GTK_TEXT_WINDOW_BOTTOM, + &text_view->bottom_window); + break; + + default: + g_warning ("Unknown GtkTextWindowType in %s", G_STRLOC); + break; + } } void -gtk_text_view_set_bottom_window_height (GtkTextView *text_view, - gint height) +gtk_text_view_set_text_window_size (GtkTextView *text_view, + gint width, + gint height) { + GtkTextWindow *win; + g_return_if_fail (GTK_IS_TEXT_VIEW (text_view)); - g_return_if_fail (height >= 0); + g_return_if_fail (width > 0); + g_return_if_fail (height > 0); + + win = text_view->text_window; - set_window_height (text_view, height, GTK_TEXT_WINDOW_BOTTOM, - &text_view->bottom_window); + if (win->requisition.width == width && + win->requisition.height == height) + return; + + win->requisition.width = width; + win->requisition.height = height; + + gtk_widget_queue_resize (GTK_WIDGET (text_view)); } + diff --git a/gtk/gtktextview.h b/gtk/gtktextview.h index 2eca2eff2b..300e3716c5 100644 --- a/gtk/gtktextview.h +++ b/gtk/gtktextview.h @@ -86,6 +86,9 @@ struct _GtkTextView { guint incremental_validate_idle; /* Idle to revalidate offscreen portions, runs after redraw */ GtkIMContext *im_context; + + gint drag_start_x; + gint drag_start_y; }; struct _GtkTextViewClass { @@ -145,7 +148,15 @@ void gtk_text_view_get_iter_at_location (GtkTextView *text_view, GtkTextIter *iter, gint x, gint y); +void gtk_text_view_get_line_yrange (GtkTextView *text_view, + const GtkTextIter *iter, + gint *y, + gint *height); +void gtk_text_view_get_line_at_y (GtkTextView *text_view, + GtkTextIter *target_iter, + gint y, + gint *line_top); void gtk_text_view_buffer_to_window_coords (GtkTextView *text_view, GtkTextWindowType win, @@ -165,18 +176,13 @@ GdkWindow* gtk_text_view_get_window (GtkTextView *text_view, GtkTextWindowType gtk_text_view_get_window_type (GtkTextView *text_view, GdkWindow *window); -void gtk_text_view_set_left_window_width (GtkTextView *text_view, - gint width); -void gtk_text_view_set_right_window_width (GtkTextView *text_view, - gint width); -void gtk_text_view_set_top_window_height (GtkTextView *text_view, - gint height); -void gtk_text_view_set_bottom_window_height (GtkTextView *text_view, - gint height); - -void gtk_text_view_set_text_window_size (GtkTextView *text_view, - gint width, - gint height); +void gtk_text_view_set_border_window_size (GtkTextView *text_view, + GtkTextWindowType type, + gint size); +void gtk_text_view_set_text_window_size (GtkTextView *text_view, + gint width, + gint height); + #ifdef __cplusplus } diff --git a/gtk/testtext.c b/gtk/testtext.c index f7f1c357b2..b787efe172 100644 --- a/gtk/testtext.c +++ b/gtk/testtext.c @@ -418,8 +418,7 @@ fill_example_buffer (GtkTextBuffer *buffer) GtkTextTag *tag; GdkColor color; GdkColor color2; - GdkPixmap *pixmap; - GdkBitmap *mask; + GdkPixbuf *pixbuf; int i; char *str; @@ -500,13 +499,10 @@ fill_example_buffer (GtkTextBuffer *buffer) "left_margin", 20, "right_margin", 20, NULL); + + - pixmap = gdk_pixmap_colormap_create_from_xpm_d (NULL, - gtk_widget_get_default_colormap (), - &mask, - NULL, book_closed_xpm); - - g_assert (pixmap != NULL); + pixbuf = gdk_pixbuf_new_from_xpm_data (book_closed_xpm); i = 0; while (i < 100) @@ -515,7 +511,7 @@ fill_example_buffer (GtkTextBuffer *buffer) gtk_text_buffer_get_iter_at_offset (buffer, &iter, 0); - gtk_text_buffer_insert_pixmap (buffer, &iter, pixmap, mask); + gtk_text_buffer_insert_pixbuf (buffer, &iter, pixbuf); str = g_strdup_printf ("%d Hello World! blah blah blah blah blah blah blah blah blah blah blah blah\nwoo woo woo woo woo woo woo woo woo woo woo woo woo woo woo\n", i); @@ -582,9 +578,7 @@ fill_example_buffer (GtkTextBuffer *buffer) ++i; } - gdk_pixmap_unref (pixmap); - if (mask) - gdk_bitmap_unref (mask); + g_object_unref (G_OBJECT (pixbuf)); printf ("%d lines %d chars\n", gtk_text_buffer_get_line_count (buffer), @@ -1408,29 +1402,170 @@ view_set_title (View *view) g_free (title); } +static void +cursor_set_callback (GtkTextBuffer *buffer, + const GtkTextIter *location, + GtkTextMark *mark, + gpointer user_data) +{ + GtkTextView *text_view; + + /* Redraw tab windows if the cursor moves + * on the mapped widget (windows may not exist before realization... + */ + + text_view = GTK_TEXT_VIEW (user_data); + + if (GTK_WIDGET_MAPPED (text_view) && + mark == gtk_text_buffer_get_insert (buffer)) + { + GdkWindow *tab_window; + + tab_window = gtk_text_view_get_window (text_view, + GTK_TEXT_WINDOW_TOP); + + gdk_window_invalidate_rect (tab_window, NULL, FALSE); + + tab_window = gtk_text_view_get_window (text_view, + GTK_TEXT_WINDOW_BOTTOM); + + gdk_window_invalidate_rect (tab_window, NULL, FALSE); + } +} + +static gint +tab_stops_expose (GtkWidget *widget, + GdkEventExpose *event, + gpointer user_data) +{ + gint first_x; + gint last_x; + gint i; + GdkWindow *top_win; + GdkWindow *bottom_win; + GtkTextView *text_view; + GtkTextWindowType type; + GdkDrawable *target; + gint *positions = NULL; + gint size; + GtkTextAttributes *attrs; + GtkTextIter insert; + GtkTextBuffer *buffer; + gboolean in_pixels; + + text_view = GTK_TEXT_VIEW (widget); + + /* See if this expose is on the tab stop window */ + top_win = gtk_text_view_get_window (text_view, + GTK_TEXT_WINDOW_TOP); + + bottom_win = gtk_text_view_get_window (text_view, + GTK_TEXT_WINDOW_BOTTOM); + + if (event->window == top_win) + { + type = GTK_TEXT_WINDOW_TOP; + target = top_win; + } + else if (event->window == bottom_win) + { + type = GTK_TEXT_WINDOW_BOTTOM; + target = bottom_win; + } + else + return FALSE; + + first_x = event->area.x; + last_x = first_x + event->area.width; + + gtk_text_view_window_to_buffer_coords (text_view, + type, + first_x, + 0, + &first_x, + NULL); + + gtk_text_view_window_to_buffer_coords (text_view, + type, + last_x, + 0, + &last_x, + NULL); + + buffer = gtk_text_view_get_buffer (text_view); + + gtk_text_buffer_get_iter_at_mark (buffer, + &insert, + gtk_text_buffer_get_mark (buffer, + "insert")); + + attrs = gtk_text_attributes_new (); + + gtk_text_iter_get_attributes (&insert, attrs); + + if (attrs->tabs) + { + size = pango_tab_array_get_size (attrs->tabs); + + pango_tab_array_get_tabs (attrs->tabs, + NULL, + &positions); + + in_pixels = pango_tab_array_get_positions_in_pixels (attrs->tabs); + } + else + { + size = 0; + in_pixels = FALSE; + } + + gtk_text_attributes_unref (attrs); + + i = 0; + while (i < size) + { + gint pos; + + if (!in_pixels) + positions[i] = PANGO_PIXELS (positions[i]); + + gtk_text_view_buffer_to_window_coords (text_view, + type, + positions[i], + 0, + &pos, + NULL); + + gdk_draw_line (target, + widget->style->fg_gc [widget->state], + pos, 0, + pos, 15); + + ++i; + } + + g_free (positions); + + return TRUE; +} + static void get_lines (GtkTextView *text_view, gint first_y, gint last_y, - gint **buffer_coords, - gint **numbers, + GArray *buffer_coords, + GArray *numbers, gint *countp) { GtkTextIter iter; gint count; - gint size; - - if (buffer_coords) - *buffer_coords = NULL; + gint size; - if (numbers) - *numbers = NULL; + g_array_set_size (buffer_coords, 0); + g_array_set_size (numbers, 0); /* Get iter at first y */ - gtk_text_view_get_iter_at_location (text_view, &iter, 0, first_y); - - /* Move back to start of its paragraph */ - gtk_text_iter_set_line_offset (&iter, 0); + gtk_text_view_get_line_at_y (text_view, &iter, first_y, NULL); /* For each iter, get its location and add it to the arrays. * Stop when we pass last_y @@ -1440,34 +1575,20 @@ get_lines (GtkTextView *text_view, while (!gtk_text_iter_is_last (&iter)) { - GdkRectangle loc; - - gtk_text_view_get_iter_location (text_view, &iter, &loc); - - if (loc.y >= last_y) - break; - - if (count >= size) - { - size = 2 * size + 2; /* + 2 handles size == 0 case */ - - if (buffer_coords) - *buffer_coords = g_realloc (*buffer_coords, - size * sizeof (gint)); - - if (numbers) - *numbers = g_realloc (*numbers, - size * sizeof (gint)); - } - - if (buffer_coords) - (*buffer_coords)[count] = loc.y; + gint y, height; + gint line_num; + + gtk_text_view_get_line_yrange (text_view, &iter, &y, &height); - if (numbers) - (*numbers)[count] = gtk_text_iter_get_line (&iter); + g_array_append_val (buffer_coords, y); + line_num = gtk_text_iter_get_line (&iter); + g_array_append_val (numbers, line_num); ++count; + if ((y + height) >= last_y) + break; + gtk_text_iter_forward_line (&iter); } @@ -1480,42 +1601,67 @@ line_numbers_expose (GtkWidget *widget, gpointer user_data) { gint count; - gint *numbers = NULL; - gint *pixels = NULL; + GArray *numbers; + GArray *pixels; gint first_y; gint last_y; gint i; GdkWindow *left_win; + GdkWindow *right_win; PangoLayout *layout; GtkTextView *text_view; - + GtkTextWindowType type; + GdkDrawable *target; + text_view = GTK_TEXT_VIEW (widget); /* See if this expose is on the line numbers window */ left_win = gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_LEFT); - if (event->window != left_win) + right_win = gtk_text_view_get_window (text_view, + GTK_TEXT_WINDOW_RIGHT); + + if (event->window == left_win) + { + type = GTK_TEXT_WINDOW_LEFT; + target = left_win; + } + else if (event->window == right_win) + { + type = GTK_TEXT_WINDOW_RIGHT; + target = right_win; + } + else return FALSE; first_y = event->area.y; last_y = first_y + event->area.height; gtk_text_view_window_to_buffer_coords (text_view, - GTK_TEXT_WINDOW_LEFT, + type, + 0, first_y, + NULL, + &first_y); + + gtk_text_view_window_to_buffer_coords (text_view, + type, + 0, last_y, - &first_y, + NULL, &last_y); + numbers = g_array_new (FALSE, FALSE, sizeof (gint)); + pixels = g_array_new (FALSE, FALSE, sizeof (gint)); + get_lines (text_view, first_y, last_y, - &pixels, - &numbers, + pixels, + numbers, &count); - - + /* Draw fully internationalized numbers! */ layout = gtk_widget_create_pango_layout (widget, ""); @@ -1527,17 +1673,18 @@ line_numbers_expose (GtkWidget *widget, gchar *str; gtk_text_view_buffer_to_window_coords (text_view, - GTK_TEXT_WINDOW_LEFT, + type, 0, - pixels[i], + g_array_index (pixels, gint, i), NULL, &pos); - str = g_strdup_printf ("%d", numbers[i]); + str = g_strdup_printf ("%d", g_array_index (numbers, gint, i)); pango_layout_set_text (layout, str, -1); - - gdk_draw_layout (left_win, + + + gdk_draw_layout (target, widget->style->fg_gc [widget->state], /* 2 is just a random padding */ 2, pos + 2, @@ -1548,8 +1695,8 @@ line_numbers_expose (GtkWidget *widget, ++i; } - g_free (pixels); - g_free (numbers); + g_array_free (pixels, TRUE); + g_array_free (numbers, TRUE); g_object_unref (G_OBJECT (layout)); @@ -1601,22 +1748,36 @@ create_view (Buffer *buffer) GTK_WRAPMODE_WORD); - /* Set sizes on these windows, just for debugging */ + /* Draw tab stops in the top and bottom windows. */ - gtk_text_view_set_right_window_width (GTK_TEXT_VIEW (view->text_view), - 30); - - gtk_text_view_set_top_window_height (GTK_TEXT_VIEW (view->text_view), - 15); + gtk_text_view_set_border_window_size (GTK_TEXT_VIEW (view->text_view), + GTK_TEXT_WINDOW_TOP, + 15); + + gtk_text_view_set_border_window_size (GTK_TEXT_VIEW (view->text_view), + GTK_TEXT_WINDOW_BOTTOM, + 15); - gtk_text_view_set_bottom_window_height (GTK_TEXT_VIEW (view->text_view), - 23); + gtk_signal_connect (GTK_OBJECT (view->text_view), + "expose_event", + GTK_SIGNAL_FUNC (tab_stops_expose), + NULL); - /* Draw line numbers in the left window; we should really be - * more scientific about what width we set it to. + gtk_signal_connect (GTK_OBJECT (view->buffer->buffer), + "mark_set", + GTK_SIGNAL_FUNC (cursor_set_callback), + view->text_view); + + /* Draw line numbers in the side windows; we should really be + * more scientific about what width we set them to. */ - gtk_text_view_set_left_window_width (GTK_TEXT_VIEW (view->text_view), - 30); + gtk_text_view_set_border_window_size (GTK_TEXT_VIEW (view->text_view), + GTK_TEXT_WINDOW_RIGHT, + 30); + + gtk_text_view_set_border_window_size (GTK_TEXT_VIEW (view->text_view), + GTK_TEXT_WINDOW_LEFT, + 30); gtk_signal_connect (GTK_OBJECT (view->text_view), "expose_event", @@ -1645,7 +1806,6 @@ main (int argc, char** argv) int i; gtk_init (&argc, &argv); - gdk_rgb_init (); /* FIXME remove this */ buffer = create_buffer (); view = create_view (buffer); diff --git a/gtk/testtextbuffer.c b/gtk/testtextbuffer.c index 8047dc62df..f5e065f546 100644 --- a/gtk/testtextbuffer.c +++ b/gtk/testtextbuffer.c @@ -260,8 +260,7 @@ fill_buffer (GtkTextBuffer *buffer) GdkColor color, color2; GtkTextIter iter; GtkTextIter iter2; - GdkPixmap *pixmap; - GdkBitmap *mask; + GdkPixbuf *pixbuf; int i; tag = gtk_text_buffer_create_tag (buffer, "fg_blue"); @@ -295,12 +294,9 @@ fill_buffer (GtkTextBuffer *buffer) "font", "-*-courier-bold-r-*-*-10-*-*-*-*-*-*-*", NULL); - pixmap = gdk_pixmap_colormap_create_from_xpm_d (NULL, - gtk_widget_get_default_colormap (), - &mask, - NULL, book_closed_xpm); + pixbuf = gdk_pixbuf_new_from_xpm_data (book_closed_xpm); - g_assert (pixmap != NULL); + g_assert (pixbuf != NULL); i = 0; while (i < 10) @@ -309,11 +305,11 @@ fill_buffer (GtkTextBuffer *buffer) gtk_text_buffer_get_iter_at_offset (buffer, &iter, 0); - gtk_text_buffer_insert_pixmap (buffer, &iter, pixmap, mask); + gtk_text_buffer_insert_pixbuf (buffer, &iter, pixbuf); gtk_text_buffer_get_iter_at_offset (buffer, &iter, 1); - gtk_text_buffer_insert_pixmap (buffer, &iter, pixmap, mask); + gtk_text_buffer_insert_pixbuf (buffer, &iter, pixbuf); str = g_strdup_printf ("%d Hello World!\nwoo woo woo woo woo woo woo woo\n", i); @@ -329,20 +325,20 @@ fill_buffer (GtkTextBuffer *buffer) "Spanish (Español) ¡Hola! / French (Français) Bonjour, Salut / German (Deutsch Süd) Grüß Gott (testing Latin-1 chars encoded in UTF8)\nThai (we can't display this, just making sure we don't crash) (ภาษาไทย) สวัสดีครับ, สวัสดีค่ะ\n", -1); - gtk_text_buffer_insert_pixmap (buffer, &iter, pixmap, mask); - gtk_text_buffer_insert_pixmap (buffer, &iter, pixmap, mask); + gtk_text_buffer_insert_pixbuf (buffer, &iter, pixbuf); + gtk_text_buffer_insert_pixbuf (buffer, &iter, pixbuf); gtk_text_buffer_get_iter_at_offset (buffer, &iter, 4); - gtk_text_buffer_insert_pixmap (buffer, &iter, pixmap, mask); + gtk_text_buffer_insert_pixbuf (buffer, &iter, pixbuf); gtk_text_buffer_get_iter_at_offset (buffer, &iter, 7); - gtk_text_buffer_insert_pixmap (buffer, &iter, pixmap, mask); + gtk_text_buffer_insert_pixbuf (buffer, &iter, pixbuf); gtk_text_buffer_get_iter_at_offset (buffer, &iter, 8); - gtk_text_buffer_insert_pixmap (buffer, &iter, pixmap, mask); + gtk_text_buffer_insert_pixbuf (buffer, &iter, pixbuf); gtk_text_buffer_get_iter_at_line_offset (buffer, &iter, 0, 8); iter2 = iter; @@ -387,9 +383,5 @@ fill_buffer (GtkTextBuffer *buffer) ++i; } - gdk_pixmap_unref (pixmap); - if (mask) - gdk_bitmap_unref (mask); + gdk_pixbuf_unref (pixbuf); } - - -- cgit v1.2.1