diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2005-11-17 10:57:35 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2005-11-17 10:57:35 (GMT) |
commit | ade22ba319d8ff4395c82135981cc073804ce97a (patch) | |
tree | 551a8431a7603d8f0d73f739344653f03f7c3a35 /generic/tkTextMark.c | |
parent | 3857560b944b318c14b18b5105c6e25d169bb9a6 (diff) | |
download | tk-ade22ba319d8ff4395c82135981cc073804ce97a.zip tk-ade22ba319d8ff4395c82135981cc073804ce97a.tar.gz tk-ade22ba319d8ff4395c82135981cc073804ce97a.tar.bz2 |
Lots of ANSIfying of function decls.
Also a few spots where code has been cleaned up more completely.
Diffstat (limited to 'generic/tkTextMark.c')
-rw-r--r-- | generic/tkTextMark.c | 658 |
1 files changed, 339 insertions, 319 deletions
diff --git a/generic/tkTextMark.c b/generic/tkTextMark.c index 4354ede..50aa4af 100644 --- a/generic/tkTextMark.c +++ b/generic/tkTextMark.c @@ -1,16 +1,16 @@ -/* +/* * tkTextMark.c -- * - * This file contains the procedure that implement marks for - * text widgets. + * This file contains the functions that implement marks for text + * widgets. * * Copyright (c) 1994 The Regents of the University of California. * Copyright (c) 1994-1997 Sun Microsystems, Inc. * - * See the file "license.terms" for information on usage and redistribution - * of this file, and for a DISCLAIMER OF ALL WARRANTIES. + * See the file "license.terms" for information on usage and redistribution of + * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkTextMark.c,v 1.15 2005/10/10 10:36:35 vincentdarley Exp $ + * RCS: @(#) $Id: tkTextMark.c,v 1.16 2005/11/17 10:57:35 dkf Exp $ */ #include "tkInt.h" @@ -25,26 +25,25 @@ + sizeof(TkTextMark))) /* - * Forward references for procedures defined in this file: + * Forward references for functions defined in this file: */ -static void InsertUndisplayProc _ANSI_ARGS_((TkText *textPtr, - TkTextDispChunk *chunkPtr)); -static int MarkDeleteProc _ANSI_ARGS_((TkTextSegment *segPtr, - TkTextLine *linePtr, int treeGone)); -static TkTextSegment * MarkCleanupProc _ANSI_ARGS_((TkTextSegment *segPtr, - TkTextLine *linePtr)); -static void MarkCheckProc _ANSI_ARGS_((TkTextSegment *segPtr, - TkTextLine *linePtr)); -static int MarkLayoutProc _ANSI_ARGS_((TkText *textPtr, - TkTextIndex *indexPtr, TkTextSegment *segPtr, - int offset, int maxX, int maxChars, - int noCharsYet, TkWrapMode wrapMode, - TkTextDispChunk *chunkPtr)); -static int MarkFindNext _ANSI_ARGS_((Tcl_Interp *interp, - TkText *textPtr, CONST char *markName)); -static int MarkFindPrev _ANSI_ARGS_((Tcl_Interp *interp, - TkText *textPtr, CONST char *markName)); +static void InsertUndisplayProc(TkText *textPtr, + TkTextDispChunk *chunkPtr); +static int MarkDeleteProc(TkTextSegment *segPtr, + TkTextLine *linePtr, int treeGone); +static TkTextSegment * MarkCleanupProc(TkTextSegment *segPtr, + TkTextLine *linePtr); +static void MarkCheckProc(TkTextSegment *segPtr, + TkTextLine *linePtr); +static int MarkLayoutProc(TkText *textPtr, TkTextIndex *indexPtr, + TkTextSegment *segPtr, int offset, int maxX, + int maxChars, int noCharsYet, TkWrapMode wrapMode, + TkTextDispChunk *chunkPtr); +static int MarkFindNext(Tcl_Interp *interp, + TkText *textPtr, CONST char *markName); +static int MarkFindPrev(Tcl_Interp *interp, + TkText *textPtr, CONST char *markName); /* @@ -55,25 +54,25 @@ static int MarkFindPrev _ANSI_ARGS_((Tcl_Interp *interp, */ Tk_SegType tkTextRightMarkType = { - "mark", /* name */ - 0, /* leftGravity */ - (Tk_SegSplitProc *) NULL, /* splitProc */ - MarkDeleteProc, /* deleteProc */ - MarkCleanupProc, /* cleanupProc */ - (Tk_SegLineChangeProc *) NULL, /* lineChangeProc */ - MarkLayoutProc, /* layoutProc */ - MarkCheckProc /* checkProc */ + "mark", /* name */ + 0, /* leftGravity */ + NULL, /* splitProc */ + MarkDeleteProc, /* deleteProc */ + MarkCleanupProc, /* cleanupProc */ + NULL, /* lineChangeProc */ + MarkLayoutProc, /* layoutProc */ + MarkCheckProc /* checkProc */ }; Tk_SegType tkTextLeftMarkType = { - "mark", /* name */ - 1, /* leftGravity */ - (Tk_SegSplitProc *) NULL, /* splitProc */ - MarkDeleteProc, /* deleteProc */ - MarkCleanupProc, /* cleanupProc */ - (Tk_SegLineChangeProc *) NULL, /* lineChangeProc */ - MarkLayoutProc, /* layoutProc */ - MarkCheckProc /* checkProc */ + "mark", /* name */ + 1, /* leftGravity */ + NULL, /* splitProc */ + MarkDeleteProc, /* deleteProc */ + MarkCleanupProc, /* cleanupProc */ + NULL, /* lineChangeProc */ + MarkLayoutProc, /* layoutProc */ + MarkCheckProc /* checkProc */ }; /* @@ -81,9 +80,9 @@ Tk_SegType tkTextLeftMarkType = { * * TkTextMarkCmd -- * - * This procedure is invoked to process the "mark" options of - * the widget command for text widgets. See the user documentation - * for details on what it does. + * This function is invoked to process the "mark" options of the widget + * command for text widgets. See the user documentation for details on + * what it does. * * Results: * A standard Tcl result. @@ -95,11 +94,11 @@ Tk_SegType tkTextLeftMarkType = { */ int -TkTextMarkCmd(textPtr, interp, objc, objv) - register TkText *textPtr; /* Information about text widget. */ - Tcl_Interp *interp; /* Current interpreter. */ - int objc; /* Number of arguments. */ - Tcl_Obj *CONST objv[]; /* Argument objects. Someone else has already +TkTextMarkCmd( + register TkText *textPtr, /* Information about text widget. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *CONST objv[]) /* Argument objects. Someone else has already * parsed this command enough to know that * objv[1] is "mark". */ { @@ -110,13 +109,13 @@ TkTextMarkCmd(textPtr, interp, objc, objv) Tk_SegType *newTypePtr; int optionIndex; - + static CONST char *markOptionStrings[] = { - "gravity", "names", "next", "previous", "set", - "unset", (char *) NULL + "gravity", "names", "next", "previous", "set", + "unset", NULL }; enum markOptions { - MARK_GRAVITY, MARK_NAMES, MARK_NEXT, MARK_PREVIOUS, + MARK_GRAVITY, MARK_NAMES, MARK_NEXT, MARK_PREVIOUS, MARK_SET, MARK_UNSET }; @@ -124,120 +123,120 @@ TkTextMarkCmd(textPtr, interp, objc, objv) Tcl_WrongNumArgs(interp, 2, objv, "option ?arg arg ...?"); return TCL_ERROR; } - if (Tcl_GetIndexFromObj(interp, objv[2], markOptionStrings, - "mark option", 0, &optionIndex) != TCL_OK) { + if (Tcl_GetIndexFromObj(interp, objv[2], markOptionStrings, "mark option", + 0, &optionIndex) != TCL_OK) { return TCL_ERROR; } switch ((enum markOptions)optionIndex) { - case MARK_GRAVITY: { - char c; - int length; - char *str; - - if (objc < 4 || objc > 5) { - Tcl_WrongNumArgs(interp, 3, objv, "markName ?gravity?"); + case MARK_GRAVITY: { + char c; + int length; + char *str; + + if (objc < 4 || objc > 5) { + Tcl_WrongNumArgs(interp, 3, objv, "markName ?gravity?"); + return TCL_ERROR; + } + str = Tcl_GetStringFromObj(objv[3],&length); + if (length == 6 && !strcmp(str, "insert")) { + markPtr = textPtr->insertMarkPtr; + } else if (length == 7 && !strcmp(str, "current")) { + markPtr = textPtr->currentMarkPtr; + } else { + hPtr = Tcl_FindHashEntry(&textPtr->sharedTextPtr->markTable, str); + if (hPtr == NULL) { + Tcl_AppendResult(interp, "there is no mark named \"", + Tcl_GetString(objv[3]), "\"", NULL); return TCL_ERROR; } - str = Tcl_GetStringFromObj(objv[3],&length); - if (length == 6 && !strcmp(str, "insert")) { - markPtr = textPtr->insertMarkPtr; - } else if (length == 7 && !strcmp(str, "current")) { - markPtr = textPtr->currentMarkPtr; - } else { - hPtr = Tcl_FindHashEntry(&textPtr->sharedTextPtr->markTable, str); - if (hPtr == NULL) { - Tcl_AppendResult(interp, "there is no mark named \"", - Tcl_GetString(objv[3]), "\"", (char *) NULL); - return TCL_ERROR; - } - markPtr = (TkTextSegment *) Tcl_GetHashValue(hPtr); - } - if (objc == 4) { - if (markPtr->typePtr == &tkTextRightMarkType) { - Tcl_SetResult(interp, "right", TCL_STATIC); - } else { - Tcl_SetResult(interp, "left", TCL_STATIC); - } - return TCL_OK; - } - str = Tcl_GetStringFromObj(objv[4],&length); - c = str[0]; - if ((c == 'l') && (strncmp(str, "left", (unsigned)length) == 0)) { - newTypePtr = &tkTextLeftMarkType; - } else if ((c == 'r') && - (strncmp(str, "right", (unsigned)length) == 0)) { - newTypePtr = &tkTextRightMarkType; + markPtr = (TkTextSegment *) Tcl_GetHashValue(hPtr); + } + if (objc == 4) { + if (markPtr->typePtr == &tkTextRightMarkType) { + Tcl_SetResult(interp, "right", TCL_STATIC); } else { - Tcl_AppendResult(interp, "bad mark gravity \"", str, - "\": must be left or right", (char *) NULL); - return TCL_ERROR; + Tcl_SetResult(interp, "left", TCL_STATIC); } - TkTextMarkSegToIndex(textPtr, markPtr, &index); - TkBTreeUnlinkSegment(markPtr, markPtr->body.mark.linePtr); - markPtr->typePtr = newTypePtr; - TkBTreeLinkSegment(markPtr, &index); - break; + return TCL_OK; } - case MARK_NAMES: { - if (objc != 3) { - Tcl_WrongNumArgs(interp, 3, objv, NULL); - return TCL_ERROR; - } - Tcl_AppendElement(interp, "insert"); - Tcl_AppendElement(interp, "current"); - for (hPtr = Tcl_FirstHashEntry(&textPtr->sharedTextPtr->markTable, &search); - hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) { - Tcl_AppendElement(interp, - Tcl_GetHashKey(&textPtr->sharedTextPtr->markTable, hPtr)); - } - break; + str = Tcl_GetStringFromObj(objv[4],&length); + c = str[0]; + if ((c == 'l') && (strncmp(str, "left", (unsigned)length) == 0)) { + newTypePtr = &tkTextLeftMarkType; + } else if ((c == 'r') && + (strncmp(str, "right", (unsigned)length) == 0)) { + newTypePtr = &tkTextRightMarkType; + } else { + Tcl_AppendResult(interp, "bad mark gravity \"", str, + "\": must be left or right", NULL); + return TCL_ERROR; } - case MARK_NEXT: { - if (objc != 4) { - Tcl_WrongNumArgs(interp, 3, objv, "index"); - return TCL_ERROR; - } - return MarkFindNext(interp, textPtr, Tcl_GetString(objv[3])); + TkTextMarkSegToIndex(textPtr, markPtr, &index); + TkBTreeUnlinkSegment(markPtr, markPtr->body.mark.linePtr); + markPtr->typePtr = newTypePtr; + TkBTreeLinkSegment(markPtr, &index); + break; + } + case MARK_NAMES: + if (objc != 3) { + Tcl_WrongNumArgs(interp, 3, objv, NULL); + return TCL_ERROR; } - case MARK_PREVIOUS: { - if (objc != 4) { - Tcl_WrongNumArgs(interp, 3, objv, "index"); - return TCL_ERROR; - } - return MarkFindPrev(interp, textPtr, Tcl_GetString(objv[3])); + Tcl_AppendElement(interp, "insert"); + Tcl_AppendElement(interp, "current"); + for (hPtr = Tcl_FirstHashEntry(&textPtr->sharedTextPtr->markTable, + &search); hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) { + Tcl_AppendElement(interp, + Tcl_GetHashKey(&textPtr->sharedTextPtr->markTable, hPtr)); } - case MARK_SET: { - if (objc != 5) { - Tcl_WrongNumArgs(interp, 3, objv, "markName index"); - return TCL_ERROR; - } - if (TkTextGetObjIndex(interp, textPtr, objv[4], &index) != TCL_OK) { - return TCL_ERROR; - } - TkTextSetMark(textPtr, Tcl_GetString(objv[3]), &index); - return TCL_OK; + break; + case MARK_NEXT: + if (objc != 4) { + Tcl_WrongNumArgs(interp, 3, objv, "index"); + return TCL_ERROR; + } + return MarkFindNext(interp, textPtr, Tcl_GetString(objv[3])); + case MARK_PREVIOUS: + if (objc != 4) { + Tcl_WrongNumArgs(interp, 3, objv, "index"); + return TCL_ERROR; + } + return MarkFindPrev(interp, textPtr, Tcl_GetString(objv[3])); + case MARK_SET: + if (objc != 5) { + Tcl_WrongNumArgs(interp, 3, objv, "markName index"); + return TCL_ERROR; } - case MARK_UNSET: { - int i; - for (i = 3; i < objc; i++) { - hPtr = Tcl_FindHashEntry(&textPtr->sharedTextPtr->markTable, - Tcl_GetString(objv[i])); - if (hPtr != NULL) { - markPtr = (TkTextSegment *) Tcl_GetHashValue(hPtr); - /* Special case not needed with peer widgets */ - if ((markPtr == textPtr->insertMarkPtr) - || (markPtr == textPtr->currentMarkPtr)) { - continue; - } - TkBTreeUnlinkSegment(markPtr, markPtr->body.mark.linePtr); - Tcl_DeleteHashEntry(hPtr); - ckfree((char *) markPtr); + if (TkTextGetObjIndex(interp, textPtr, objv[4], &index) != TCL_OK) { + return TCL_ERROR; + } + TkTextSetMark(textPtr, Tcl_GetString(objv[3]), &index); + return TCL_OK; + case MARK_UNSET: { + int i; + + for (i = 3; i < objc; i++) { + hPtr = Tcl_FindHashEntry(&textPtr->sharedTextPtr->markTable, + Tcl_GetString(objv[i])); + if (hPtr != NULL) { + markPtr = (TkTextSegment *) Tcl_GetHashValue(hPtr); + + /* + * Special case not needed with peer widgets. + */ + + if ((markPtr == textPtr->insertMarkPtr) + || (markPtr == textPtr->currentMarkPtr)) { + continue; } + TkBTreeUnlinkSegment(markPtr, markPtr->body.mark.linePtr); + Tcl_DeleteHashEntry(hPtr); + ckfree((char *) markPtr); } - break; } - + break; + } } return TCL_OK; } @@ -247,8 +246,8 @@ TkTextMarkCmd(textPtr, interp, objc, objv) * * TkTextSetMark -- * - * Set a mark to a particular position, creating a new mark if - * one doesn't already exist. + * Set a mark to a particular position, creating a new mark if one + * doesn't already exist. * * Results: * The return value is a pointer to the mark that was just set. @@ -260,50 +259,54 @@ TkTextMarkCmd(textPtr, interp, objc, objv) */ TkTextSegment * -TkTextSetMark(textPtr, name, indexPtr) - TkText *textPtr; /* Text widget in which to create mark. */ - CONST char *name; /* Name of mark to set. */ - TkTextIndex *indexPtr; /* Where to set mark. */ +TkTextSetMark( + TkText *textPtr, /* Text widget in which to create mark. */ + CONST char *name, /* Name of mark to set. */ + TkTextIndex *indexPtr) /* Where to set mark. */ { Tcl_HashEntry *hPtr = NULL; TkTextSegment *markPtr; TkTextIndex insertIndex; - int new; + int isNew; int widgetSpecific; - + if (!strcmp(name, "insert")) { widgetSpecific = 1; markPtr = textPtr->insertMarkPtr; - new = (markPtr == NULL ? 1 : 0); + isNew = (markPtr == NULL ? 1 : 0); } else if (!strcmp(name, "current")) { widgetSpecific = 2; markPtr = textPtr->currentMarkPtr; - new = (markPtr == NULL ? 1 : 0); + isNew = (markPtr == NULL ? 1 : 0); } else { widgetSpecific = 0; - hPtr = Tcl_CreateHashEntry(&textPtr->sharedTextPtr->markTable, name, &new); + hPtr = Tcl_CreateHashEntry(&textPtr->sharedTextPtr->markTable, name, + &isNew); markPtr = (TkTextSegment *) Tcl_GetHashValue(hPtr); } - if (!new) { + if (!isNew) { /* - * If this is the insertion point that's being moved, be sure - * to force a display update at the old position. Also, don't - * let the insertion cursor be after the final newline of the - * file. + * If this is the insertion point that's being moved, be sure to force + * a display update at the old position. Also, don't let the insertion + * cursor be after the final newline of the file. */ if (markPtr == textPtr->insertMarkPtr) { TkTextIndex index, index2; + TkTextMarkSegToIndex(textPtr, textPtr->insertMarkPtr, &index); TkTextIndexForwChars(NULL,&index, 1, &index2, COUNT_INDICES); - /* - * While we wish to redisplay, no heights have changed, so - * no need to call TkTextInvalidateLineMetrics. + + /* + * While we wish to redisplay, no heights have changed, so no need + * to call TkTextInvalidateLineMetrics. */ + TkTextChanged(NULL, textPtr, &index, &index2); - if (TkBTreeLinesTo(textPtr, indexPtr->linePtr) - == TkBTreeNumLines(textPtr->sharedTextPtr->tree, textPtr)) { - TkTextIndexBackChars(NULL,indexPtr, 1, &insertIndex, COUNT_INDICES); + if (TkBTreeLinesTo(textPtr, indexPtr->linePtr) == + TkBTreeNumLines(textPtr->sharedTextPtr->tree, textPtr)) { + TkTextIndexBackChars(NULL,indexPtr, 1, &insertIndex, + COUNT_INDICES); indexPtr = &insertIndex; } } @@ -334,10 +337,12 @@ TkTextSetMark(textPtr, name, indexPtr) TkTextIndex index2; TkTextIndexForwChars(NULL,indexPtr, 1, &index2, COUNT_INDICES); - /* - * While we wish to redisplay, no heights have changed, so - * no need to call TkTextInvalidateLineMetrics + + /* + * While we wish to redisplay, no heights have changed, so no need to + * call TkTextInvalidateLineMetrics */ + TkTextChanged(NULL, textPtr, indexPtr, &index2); } return markPtr; @@ -348,9 +353,9 @@ TkTextSetMark(textPtr, name, indexPtr) * * TkTextMarkSegToIndex -- * - * Given a segment that is a mark, create an index that - * refers to the next text character (or other text segment - * with non-zero size) after the mark. + * Given a segment that is a mark, create an index that refers to the + * next text character (or other text segment with non-zero size) after + * the mark. * * Results: * *IndexPtr is filled in with index information. @@ -362,10 +367,10 @@ TkTextSetMark(textPtr, name, indexPtr) */ void -TkTextMarkSegToIndex(textPtr, markPtr, indexPtr) - TkText *textPtr; /* Text widget containing mark. */ - TkTextSegment *markPtr; /* Mark segment. */ - TkTextIndex *indexPtr; /* Index information gets stored here. */ +TkTextMarkSegToIndex( + TkText *textPtr, /* Text widget containing mark. */ + TkTextSegment *markPtr, /* Mark segment. */ + TkTextIndex *indexPtr) /* Index information gets stored here. */ { TkTextSegment *segPtr; @@ -383,15 +388,14 @@ TkTextMarkSegToIndex(textPtr, markPtr, indexPtr) * * TkTextMarkNameToIndex -- * - * Given the name of a mark, return an index corresponding - * to the mark name. + * Given the name of a mark, return an index corresponding to the mark + * name. * * Results: - * The return value is TCL_OK if "name" exists as a mark in - * the text widget. In this case *indexPtr is filled in with - * the next segment whose after the mark whose size is - * non-zero. TCL_ERROR is returned if the mark doesn't exist - * in the text widget. + * The return value is TCL_OK if "name" exists as a mark in the text + * widget. In this case *indexPtr is filled in with the next segment + * whose after the mark whose size is non-zero. TCL_ERROR is returned if + * the mark doesn't exist in the text widget. * * Side effects: * None. @@ -400,17 +404,17 @@ TkTextMarkSegToIndex(textPtr, markPtr, indexPtr) */ int -TkTextMarkNameToIndex(textPtr, name, indexPtr) - TkText *textPtr; /* Text widget containing mark. */ - CONST char *name; /* Name of mark. */ - TkTextIndex *indexPtr; /* Index information gets stored here. */ +TkTextMarkNameToIndex( + TkText *textPtr, /* Text widget containing mark. */ + CONST char *name, /* Name of mark. */ + TkTextIndex *indexPtr) /* Index information gets stored here. */ { TkTextSegment *segPtr; if (textPtr == NULL) { return TCL_ERROR; } - + if (!strcmp(name, "insert")) { segPtr = textPtr->insertMarkPtr; } else if (!strcmp(name, "current")) { @@ -432,27 +436,27 @@ TkTextMarkNameToIndex(textPtr, name, indexPtr) * * MarkDeleteProc -- * - * This procedure is invoked by the text B-tree code whenever - * a mark lies in a range of characters being deleted. + * This function is invoked by the text B-tree code whenever a mark lies + * in a range of characters being deleted. * * Results: * Returns 1 to indicate that deletion has been rejected. * * Side effects: - * None (even if the whole tree is being deleted we don't - * free up the mark; it will be done elsewhere). + * None (even if the whole tree is being deleted we don't free up the + * mark; it will be done elsewhere). * *-------------------------------------------------------------- */ /* ARGSUSED */ static int -MarkDeleteProc(segPtr, linePtr, treeGone) - TkTextSegment *segPtr; /* Segment being deleted. */ - TkTextLine *linePtr; /* Line containing segment. */ - int treeGone; /* Non-zero means the entire tree is - * being deleted, so everything must - * get cleaned up. */ +MarkDeleteProc( + TkTextSegment *segPtr, /* Segment being deleted. */ + TkTextLine *linePtr, /* Line containing segment. */ + int treeGone) /* Non-zero means the entire tree is being + * deleted, so everything must get cleaned + * up. */ { return 1; } @@ -462,8 +466,8 @@ MarkDeleteProc(segPtr, linePtr, treeGone) * * MarkCleanupProc -- * - * This procedure is invoked by the B-tree code whenever a - * mark segment is moved from one line to another. + * This function is invoked by the B-tree code whenever a mark segment is + * moved from one line to another. * * Results: * None. @@ -475,9 +479,9 @@ MarkDeleteProc(segPtr, linePtr, treeGone) */ static TkTextSegment * -MarkCleanupProc(markPtr, linePtr) - TkTextSegment *markPtr; /* Mark segment that's being moved. */ - TkTextLine *linePtr; /* Line that now contains segment. */ +MarkCleanupProc( + TkTextSegment *markPtr, /* Mark segment that's being moved. */ + TkTextLine *linePtr) /* Line that now contains segment. */ { markPtr->body.mark.linePtr = linePtr; return markPtr; @@ -488,13 +492,13 @@ MarkCleanupProc(markPtr, linePtr) * * MarkLayoutProc -- * - * This procedure is the "layoutProc" for mark segments. + * This function is the "layoutProc" for mark segments. * * Results: - * If the mark isn't the insertion cursor then the return - * value is -1 to indicate that this segment shouldn't be - * displayed. If the mark is the insertion character then - * 1 is returned and the chunkPtr structure is filled in. + * If the mark isn't the insertion cursor then the return value is -1 to + * indicate that this segment shouldn't be displayed. If the mark is the + * insertion character then 1 is returned and the chunkPtr structure is + * filled in. * * Side effects: * None, except for filling in chunkPtr. @@ -504,24 +508,23 @@ MarkCleanupProc(markPtr, linePtr) /*ARGSUSED*/ static int -MarkLayoutProc(textPtr, indexPtr, segPtr, offset, maxX, maxChars, - noCharsYet, wrapMode, chunkPtr) - TkText *textPtr; /* Text widget being layed out. */ - TkTextIndex *indexPtr; /* Identifies first character in chunk. */ - TkTextSegment *segPtr; /* Segment corresponding to indexPtr. */ - int offset; /* Offset within segPtr corresponding to +MarkLayoutProc( + TkText *textPtr, /* Text widget being layed out. */ + TkTextIndex *indexPtr, /* Identifies first character in chunk. */ + TkTextSegment *segPtr, /* Segment corresponding to indexPtr. */ + int offset, /* Offset within segPtr corresponding to * indexPtr (always 0). */ - int maxX; /* Chunk must not occupy pixels at this + 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 + 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. */ - TkWrapMode wrapMode; /* Not used. */ - register TkTextDispChunk *chunkPtr; - /* Structure to fill in with information - * about this chunk. The x field has already - * been set by the caller. */ + TkWrapMode wrapMode, /* Not used. */ + register TkTextDispChunk *chunkPtr) + /* Structure to fill in with information about + * this chunk. The x field has already been + * set by the caller. */ { if (segPtr != textPtr->insertMarkPtr) { return -1; @@ -529,8 +532,8 @@ MarkLayoutProc(textPtr, indexPtr, segPtr, offset, maxX, maxChars, chunkPtr->displayProc = TkTextInsertDisplayProc; chunkPtr->undisplayProc = InsertUndisplayProc; - chunkPtr->measureProc = (Tk_ChunkMeasureProc *) NULL; - chunkPtr->bboxProc = (Tk_ChunkBboxProc *) NULL; + chunkPtr->measureProc = NULL; + chunkPtr->bboxProc = NULL; chunkPtr->numBytes = 0; chunkPtr->minAscent = 0; chunkPtr->minDescent = 0; @@ -538,9 +541,8 @@ MarkLayoutProc(textPtr, indexPtr, segPtr, offset, maxX, maxChars, chunkPtr->width = 0; /* - * Note: can't break a line after the insertion cursor: this - * prevents the insertion cursor from being stranded at the end - * of a line. + * Note: can't break a line after the insertion cursor: this prevents the + * insertion cursor from being stranded at the end of a line. */ chunkPtr->breakIndex = -1; @@ -553,8 +555,7 @@ MarkLayoutProc(textPtr, indexPtr, segPtr, offset, maxX, maxChars, * * TkTextInsertDisplayProc -- * - * This procedure is called to display the insertion - * cursor. + * This function is called to display the insertion cursor. * * Results: * None. @@ -567,32 +568,31 @@ MarkLayoutProc(textPtr, indexPtr, segPtr, offset, maxX, maxChars, /* ARGSUSED */ void -TkTextInsertDisplayProc(textPtr, chunkPtr, x, y, height, baseline, display, - dst, screenY) - TkText *textPtr; /* The current text widget. */ - TkTextDispChunk *chunkPtr; /* Chunk that is to be drawn. */ - int x; /* X-position in dst at which to - * draw this chunk (may differ from - * the x-position in the chunk because - * of scrolling). */ - int y; /* Y-position at which to draw this - * chunk in dst (x-position is in - * the chunk itself). */ - int height; /* 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 - * chunk. */ - int screenY; /* Y-coordinate in text window that - * corresponds to y. */ +TkTextInsertDisplayProc( + TkText *textPtr, /* The current text widget. */ + TkTextDispChunk *chunkPtr, /* Chunk that is to be drawn. */ + int x, /* X-position in dst at which to draw this + * chunk (may differ from the x-position in + * the chunk because of scrolling). */ + int y, /* Y-position at which to draw this chunk in + * dst (x-position is in the chunk itself). */ + int height, /* 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 chunk. */ + int screenY) /* Y-coordinate in text window that + * corresponds to y. */ { - /* We have no need for the clientData */ + /* + * We have no need for the clientData. + */ + /* TkText *textPtr = (TkText *) chunkPtr->clientData; */ TkTextIndex index; int halfWidth = textPtr->insertWidth/2; int rightSideWidth; int ix = 0, iy = 0, iw = 0, ih = 0, charWidth = 0; - + if(textPtr->insertCursorType) { TkTextMarkSegToIndex(textPtr, textPtr->insertMarkPtr, &index); TkTextIndexBbox(textPtr, &index, &ix, &iy, &iw, &ih, &charWidth); @@ -600,11 +600,11 @@ TkTextInsertDisplayProc(textPtr, chunkPtr, x, y, height, baseline, display, } else { rightSideWidth = halfWidth; } - + if ((x + rightSideWidth) < 0) { /* - * The insertion cursor is off-screen. - * Indicate caret at 0,0 and return. + * The insertion cursor is off-screen. Indicate caret at 0,0 and + * return. */ Tk_SetCaretPos(textPtr->tkwin, 0, 0, height); @@ -614,11 +614,11 @@ TkTextInsertDisplayProc(textPtr, chunkPtr, x, y, height, baseline, display, Tk_SetCaretPos(textPtr->tkwin, x - halfWidth, screenY, height); /* - * As a special hack to keep the cursor visible on mono displays - * (or anywhere else that the selection and insertion cursors - * have the same color) write the default background in the cursor - * area (instead of nothing) when the cursor isn't on. Otherwise - * the selection might hide the cursor. + * As a special hack to keep the cursor visible on mono displays (or + * anywhere else that the selection and insertion cursors have the same + * color) write the default background in the cursor area (instead of + * nothing) when the cursor isn't on. Otherwise the selection might hide + * the cursor. */ if (textPtr->flags & INSERT_ON) { @@ -637,9 +637,8 @@ TkTextInsertDisplayProc(textPtr, chunkPtr, x, y, height, baseline, display, * * InsertUndisplayProc -- * - * This procedure is called when the insertion cursor is no - * longer at a visible point on the display. It does nothing - * right now. + * This function is called when the insertion cursor is no longer at a + * visible point on the display. It does nothing right now. * * Results: * None. @@ -652,10 +651,9 @@ TkTextInsertDisplayProc(textPtr, chunkPtr, x, y, height, baseline, display, /* ARGSUSED */ static void -InsertUndisplayProc(textPtr, chunkPtr) - TkText *textPtr; /* Overall information about text - * widget. */ - TkTextDispChunk *chunkPtr; /* Chunk that is about to be freed. */ +InsertUndisplayProc( + TkText *textPtr, /* Overall information about text widget. */ + TkTextDispChunk *chunkPtr) /* Chunk that is about to be freed. */ { return; } @@ -665,23 +663,23 @@ InsertUndisplayProc(textPtr, chunkPtr) * * MarkCheckProc -- * - * This procedure is invoked by the B-tree code to perform - * consistency checks on mark segments. + * This function is invoked by the B-tree code to perform consistency + * checks on mark segments. * * Results: * None. * * Side effects: - * The procedure panics if it detects anything wrong with + * The function panics if it detects anything wrong with * the mark. * *-------------------------------------------------------------- */ static void -MarkCheckProc(markPtr, linePtr) - TkTextSegment *markPtr; /* Segment to check. */ - TkTextLine *linePtr; /* Line containing segment. */ +MarkCheckProc( + TkTextSegment *markPtr, /* Segment to check. */ + TkTextLine *linePtr) /* Line containing segment. */ { Tcl_HashSearch search; Tcl_HashEntry *hPtr; @@ -690,9 +688,10 @@ MarkCheckProc(markPtr, linePtr) Tcl_Panic("MarkCheckProc: markPtr->body.mark.linePtr bogus"); } - /* - * These two marks are not in the hash table + /* + * These two marks are not in the hash table */ + if (markPtr->body.mark.textPtr->insertMarkPtr == markPtr) { return; } @@ -701,11 +700,11 @@ MarkCheckProc(markPtr, linePtr) } /* - * Make sure that the mark is still present in the text's mark - * hash table. + * Make sure that the mark is still present in the text's mark hash table. */ - for (hPtr = Tcl_FirstHashEntry(&markPtr->body.mark.textPtr->sharedTextPtr->markTable, + for (hPtr = Tcl_FirstHashEntry( + &markPtr->body.mark.textPtr->sharedTextPtr->markTable, &search); hPtr != markPtr->body.mark.hPtr; hPtr = Tcl_NextHashEntry(&search)) { if (hPtr == NULL) { @@ -719,7 +718,7 @@ MarkCheckProc(markPtr, linePtr) * * MarkFindNext -- * - * This procedure searches forward for the next mark. + * This function searches forward for the next mark. * * Results: * A standard Tcl result, which is a mark name or an empty string. @@ -731,10 +730,10 @@ MarkCheckProc(markPtr, linePtr) */ static int -MarkFindNext(interp, textPtr, string) - Tcl_Interp *interp; /* For error reporting */ - TkText *textPtr; /* The widget */ - CONST char *string; /* The starting index or mark name */ +MarkFindNext( + Tcl_Interp *interp, /* For error reporting */ + TkText *textPtr, /* The widget */ + CONST char *string) /* The starting index or mark name */ { TkTextIndex index; Tcl_HashEntry *hPtr; @@ -754,32 +753,36 @@ MarkFindNext(interp, textPtr, string) if (hPtr != NULL) { /* * If given a mark name, return the next mark in the list of - * segments, even if it happens to be at the same character position. + * segments, even if it happens to be at the same character + * position. */ + segPtr = (TkTextSegment *) Tcl_GetHashValue(hPtr); TkTextMarkSegToIndex(textPtr, segPtr, &index); segPtr = segPtr->nextPtr; } else { /* - * For non-mark name indices we want to return any marks that - * are right at the index. + * For non-mark name indices we want to return any marks that are + * right at the index. */ + if (TkTextGetIndex(interp, textPtr, string, &index) != TCL_OK) { return TCL_ERROR; } - for (offset = 0, segPtr = index.linePtr->segPtr; + for (offset = 0, segPtr = index.linePtr->segPtr; segPtr != NULL && offset < index.byteIndex; - offset += segPtr->size, segPtr = segPtr->nextPtr) { + offset += segPtr->size, segPtr = segPtr->nextPtr) { /* Empty loop body */ ; } } } - + while (1) { /* - * segPtr points at the first possible candidate, - * or NULL if we ran off the end of the line. + * segPtr points at the first possible candidate, or NULL if we ran + * off the end of the line. */ + for ( ; segPtr != NULL ; segPtr = segPtr->nextPtr) { if (segPtr->typePtr == &tkTextRightMarkType || segPtr->typePtr == &tkTextLeftMarkType) { @@ -788,19 +791,21 @@ MarkFindNext(interp, textPtr, string) } else if (segPtr == textPtr->insertMarkPtr) { Tcl_SetResult(interp, "insert", TCL_STATIC); } else if (segPtr->body.mark.textPtr != textPtr) { - /* Ignore widget-specific marks for the other widgets */ + /* + * Ignore widget-specific marks for the other widgets. + */ + continue; } else { Tcl_SetResult(interp, - Tcl_GetHashKey(&textPtr->sharedTextPtr->markTable, - segPtr->body.mark.hPtr), - TCL_STATIC); + Tcl_GetHashKey(&textPtr->sharedTextPtr->markTable, + segPtr->body.mark.hPtr), TCL_STATIC); } return TCL_OK; } } index.linePtr = TkBTreeNextLine(textPtr, index.linePtr); - if (index.linePtr == (TkTextLine *) NULL) { + if (index.linePtr == NULL) { return TCL_OK; } index.byteIndex = 0; @@ -813,7 +818,7 @@ MarkFindNext(interp, textPtr, string) * * MarkFindPrev -- * - * This procedure searches backwards for the previous mark. + * This function searches backwards for the previous mark. * * Results: * A standard Tcl result, which is a mark name or an empty string. @@ -825,10 +830,10 @@ MarkFindNext(interp, textPtr, string) */ static int -MarkFindPrev(interp, textPtr, string) - Tcl_Interp *interp; /* For error reporting */ - TkText *textPtr; /* The widget */ - CONST char *string; /* The starting index or mark name */ +MarkFindPrev( + Tcl_Interp *interp, /* For error reporting */ + TkText *textPtr, /* The widget */ + CONST char *string) /* The starting index or mark name */ { TkTextIndex index; Tcl_HashEntry *hPtr; @@ -846,31 +851,36 @@ MarkFindPrev(interp, textPtr, string) if (hPtr != NULL) { /* * If given a mark name, return the previous mark in the list of - * segments, even if it happens to be at the same character position. + * segments, even if it happens to be at the same character + * position. */ + segPtr = (TkTextSegment *) Tcl_GetHashValue(hPtr); TkTextMarkSegToIndex(textPtr, segPtr, &index); } else { /* - * For non-mark name indices we do not return any marks that - * are right at the index. + * For non-mark name indices we do not return any marks that are + * right at the index. */ + if (TkTextGetIndex(interp, textPtr, string, &index) != TCL_OK) { return TCL_ERROR; } - for (offset = 0, segPtr = index.linePtr->segPtr; + for (offset = 0, segPtr = index.linePtr->segPtr; segPtr != NULL && offset < index.byteIndex; offset += segPtr->size, segPtr = segPtr->nextPtr) { - /* Empty loop body */ ; + /* Empty loop body */ } } } + while (1) { /* - * segPtr points just past the first possible candidate, - * or at the begining of the line. + * segPtr points just past the first possible candidate, or at the + * begining of the line. */ - for (prevPtr = NULL, seg2Ptr = index.linePtr->segPtr; + + for (prevPtr = NULL, seg2Ptr = index.linePtr->segPtr; seg2Ptr != NULL && seg2Ptr != segPtr; seg2Ptr = seg2Ptr->nextPtr) { if (seg2Ptr->typePtr == &tkTextRightMarkType || @@ -884,20 +894,30 @@ MarkFindPrev(interp, textPtr, string) } else if (prevPtr == textPtr->insertMarkPtr) { Tcl_SetResult(interp, "insert", TCL_STATIC); } else if (prevPtr->body.mark.textPtr != textPtr) { - /* Ignore widget-specific marks for the other widgets */ + /* + * Ignore widget-specific marks for the other widgets. + */ + continue; } else { - Tcl_SetResult(interp, - Tcl_GetHashKey(&textPtr->sharedTextPtr->markTable, - prevPtr->body.mark.hPtr), - TCL_STATIC); + Tcl_SetResult(interp, + Tcl_GetHashKey(&textPtr->sharedTextPtr->markTable, + prevPtr->body.mark.hPtr), TCL_STATIC); } return TCL_OK; } index.linePtr = TkBTreePreviousLine(textPtr, index.linePtr); - if (index.linePtr == (TkTextLine *) NULL) { + if (index.linePtr == NULL) { return TCL_OK; } segPtr = NULL; } } + +/* + * Local Variables: + * mode: c + * c-basic-offset: 4 + * fill-column: 78 + * End: + */ |