/*
* tkTextTag.c --
*
* This module implements the "tag" subcommand of the widget command
* for text widgets, plus most of the other high-level functions
* related to tags.
*
* Copyright (c) 1992-1994 The Regents of the University of California.
* Copyright (c) 1994-1995 Sun Microsystems, Inc.
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* SCCS: @(#) tkTextTag.c 1.36 96/03/07 15:30:43
*/
#include "tkInt.h"
#include "tkText.h"
#include "tkDefault.h"
/*
* Information used for parsing tag configuration information:
*/
(char *) NULL, 0, 0}
};
/*
* Forward declarations for procedures defined later in this file:
*/
TkTextTag **tagArrayPtr));
/*
*--------------------------------------------------------------
*
* TkTextTagCmd --
*
* This procedure is invoked to process the "tag" options of
* the widget command for text widgets. See the user documentation
* for details on what it does.
*
* Results:
* A standard Tcl result.
*
* Side effects:
* See the user documentation.
*
*--------------------------------------------------------------
*/
int
int argc; /* Number of arguments. */
char **argv; /* Argument strings. Someone else has already
* parsed this command enough to know that
* argv[1] is "tag". */
{
int c, i, addTag;
char *fullOption;
if (argc < 3) {
return TCL_ERROR;
}
c = argv[2][0];
fullOption = "add";
addTag = 1;
if (argc < 5) {
" tagName index1 ?index2 index1 index2 ...?\"",
(char *) NULL);
return TCL_ERROR;
}
return TCL_ERROR;
}
if (argc > (i+1)) {
!= TCL_OK) {
return TCL_ERROR;
}
return TCL_OK;
}
} else {
}
if (tagPtr->affectsDisplay) {
} else {
/*
* have changed.
*/
}
/*
* If the tag is "sel" then grab the selection if we're supposed
* to export it and don't already have it. Also, invalidate
* partially-completed selection retrievals.
*/
}
}
}
argv[0], " tag bind tagName ?sequence? ?command?\"",
(char *) NULL);
return TCL_ERROR;
}
/*
* Make a binding table if the widget doesn't already have
* one.
*/
}
if (argc == 6) {
int append = 0;
unsigned long mask;
if (argv[5][0] == 0) {
}
argv[5]++;
append = 1;
}
if (mask == 0) {
return TCL_ERROR;
}
"events may be used", (char *) NULL);
return TCL_ERROR;
}
} else if (argc == 5) {
char *command;
return TCL_ERROR;
}
} else {
(ClientData) tagPtr);
}
&& (length >= 2)) {
if (argc != 5) {
argv[0], " tag cget tagName option\"",
(char *) NULL);
return TCL_ERROR;
}
return TCL_ERROR;
}
&& (length >= 2)) {
if (argc < 4) {
argv[0], " tag configure tagName ?option? ?value? ",
"?option value ...?\"", (char *) NULL);
return TCL_ERROR;
}
if (argc == 4) {
} else if (argc == 5) {
} else {
int result;
/*
* Some of the configuration options, like -underline
* and -justify, require additional translation (this is
* needed because we need to distinguish a particular value
* of an option from "unspecified").
*/
return TCL_ERROR;
}
if (tagPtr->borderWidth < 0) {
tagPtr->borderWidth = 0;
}
}
return TCL_ERROR;
}
}
return TCL_ERROR;
}
}
return TCL_ERROR;
}
}
return TCL_ERROR;
}
}
return TCL_ERROR;
}
}
return TCL_ERROR;
}
}
return TCL_ERROR;
}
}
return TCL_ERROR;
}
}
}
return TCL_ERROR;
}
}
}
return TCL_ERROR;
}
}
}
}
return TCL_ERROR;
}
}
return TCL_ERROR;
}
}
"\": must be char, none, or word", (char *) NULL);
return TCL_ERROR;
}
/*
* If the "sel" tag was changed, be sure to mirror information
* from the tag back into the text widget record. NOTE: we
* don't have to free up information in the widget record
* before overwriting it, because it was mirrored in the tag
* and hence freed when the tag field was overwritten.
*/
}
tagPtr->affectsDisplay = 0;
}
return result;
}
if (argc < 4) {
argv[0], " tag delete tagName tagName ...\"",
(char *) NULL);
return TCL_ERROR;
}
for (i = 3; i < argc; i++) {
continue;
}
continue;
}
if (tagPtr->affectsDisplay) {
}
tagPtr, 0);
(ClientData) tagPtr);
}
/*
* Update the tag priorities to reflect the deletion of this tag.
*/
}
int prio;
argv[0], " tag lower tagName ?belowThis?\"",
(char *) NULL);
return TCL_ERROR;
}
return TCL_ERROR;
}
if (argc == 5) {
return TCL_ERROR;
}
} else {
}
} else {
prio = 0;
}
&& (length >= 2)) {
int arraySize;
argv[0], " tag names ?index?\"",
(char *) NULL);
return TCL_ERROR;
}
if (argc == 3) {
}
} else {
!= TCL_OK) {
return TCL_ERROR;
}
return TCL_OK;
}
}
for (i = 0; i < arraySize; i++) {
}
&& (length >= 2)) {
argv[0], " tag nextrange tagName index1 ?index2?\"",
(char *) NULL);
return TCL_ERROR;
}
return TCL_OK;
}
return TCL_ERROR;
}
0, &last);
if (argc == 5) {
!= TCL_OK) {
return TCL_ERROR;
}
/*
* The search below is a bit tricky. Rather than use the B-tree
* facilities to stop the search at index2, let it search up
* until the end of the file but check for a position past index2
* ourselves. The reason for doing it this way is that we only
* care whether the *start* of the range is before index2; once
* we find the start, we don't want TkBTreeNextTag to abort the
* search because the end of the range is after index2.
*/
int offset;
/*
* The first character is tagged. See if there is an
* on-toggle just before the character. If not, then
* skip to the end of this tagged range.
*/
offset >= 0;
goto gotStart;
}
}
if (!TkBTreeNextTag(&tSearch)) {
return TCL_OK;
}
}
/*
* Find the start of the tagged range.
*/
if (!TkBTreeNextTag(&tSearch)) {
return TCL_OK;
}
return TCL_OK;
}
&& (length >= 2)) {
argv[0], " tag prevrange tagName index1 ?index2?\"",
(char *) NULL);
return TCL_ERROR;
}
return TCL_OK;
}
return TCL_ERROR;
}
if (argc == 5) {
!= TCL_OK) {
return TCL_ERROR;
}
/*
* The search below is a bit weird. The previous toggle can be
* either an on or off toggle. If it is an on toggle, then we
* need to turn around and search forward for the end toggle.
* Otherwise we keep searching backwards.
*/
if (!TkBTreePrevTag(&tSearch)) {
return TCL_OK;
}
0, &last);
} else {
return TCL_OK;
}
}
&& (length >= 3)) {
int prio;
argv[0], " tag raise tagName ?aboveThis?\"",
(char *) NULL);
return TCL_ERROR;
}
return TCL_ERROR;
}
if (argc == 5) {
return TCL_ERROR;
}
} else {
}
} else {
}
&& (length >= 3)) {
if (argc != 4) {
return TCL_ERROR;
}
return TCL_OK;
}
0, &last);
}
while (TkBTreeNextTag(&tSearch)) {
}
&& (length >= 2)) {
fullOption = "remove";
addTag = 0;
goto addAndRemove;
} else {
"\": must be add, bind, cget, configure, delete, lower, ",
"names, nextrange, raise, ranges, or remove",
(char *) NULL);
return TCL_ERROR;
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* TkTextCreateTag --
*
* Find the record describing a tag within a given text widget,
* creating a new record if one doesn't already exist.
*
* Results:
* The return value is a pointer to the TkTextTag record for tagName.
*
* Side effects:
* A new tag record is created if there isn't one already defined
* for tagName.
*
*----------------------------------------------------------------------
*/
char *tagName; /* Name of desired tag. */
{
int new;
if (!new) {
}
/*
* No existing entry. Create a new one, initialize it, and add a
* pointer to it to the hash table entry.
*/
tagPtr->toggleCount = 0;
tagPtr->borderWidth = 0;
tagPtr->overstrike = 0;
tagPtr->affectsDisplay = 0;
return tagPtr;
}
/*
*----------------------------------------------------------------------
*
* FindTag --
*
* See if tag is defined for a given widget.
*
* Results:
* If tagName is defined in textPtr, a pointer to its TkTextTag
* structure is returned. Otherwise NULL is returned and an
* error message is recorded in interp->result unless interp
* is NULL.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
static TkTextTag *
* if NULL, then don't record an error
* message. */
char *tagName; /* Name of desired tag. */
{
}
"\" isn't defined in text widget", (char *) NULL);
}
return NULL;
}
/*
*----------------------------------------------------------------------
*
* TkTextFreeTag --
*
* This procedure is called when a tag is deleted to free up the
* memory and other resources associated with the tag.
*
* Results:
* None.
*
* Side effects:
* Memory and other resources are freed.
*
*----------------------------------------------------------------------
*/
void
{
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
/*
*----------------------------------------------------------------------
*
* SortTags --
*
* This procedure sorts an array of tag pointers in increasing
* order of priority, optimizing for the common case where the
* array is small.
*
* Results:
* None.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
static void
int numTags; /* Number of tag pointers at *tagArrayPtr. */
{
int i, j, prio;
if (numTags < 2) {
return;
}
if (numTags < 20) {
}
}
*maxPtrPtr = *tagArrayPtr;
*tagArrayPtr = tmp;
}
} else {
}
}
/*
*----------------------------------------------------------------------
*
* TagSortProc --
*
* This procedure is called by qsort when sorting an array of
* tags in priority order.
*
* Results:
* The return value is -1 if the first argument should be before
* the second element (i.e. it has lower priority), 0 if it's
* equivalent (this should never happen!), and 1 if it should be
* after the second element.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
static int
{
}
/*
*----------------------------------------------------------------------
*
* ChangeTagPriority --
*
* This procedure changes the priority of a tag by modifying
* its priority and the priorities of other tags that are affected
* by the change.
*
* Results:
* None.
*
* Side effects:
* Priorities may be changed for some or all of the tags in
* textPtr. The tags will be arranged so that there is exactly
* one tag at each priority level between 0 and textPtr->numTags-1,
* with tagPtr at priority "prio".
*
*----------------------------------------------------------------------
*/
static void
* changed. */
int prio; /* New priority for tag. */
{
if (prio < 0) {
prio = 0;
}
}
return;
delta = 1;
} else {
delta = -1;
}
}
}
}
/*
*--------------------------------------------------------------
*
* TkTextBindProc --
*
* This procedure is invoked by the Tk dispatcher to handle
* events associated with bindings on items.
*
* Results:
* None.
*
* Side effects:
* Depends on the command invoked as part of the binding
* (if there was any).
*
*--------------------------------------------------------------
*/
void
* happened. */
{
int repick = 0;
/*
* This code simulates grabs for mouse buttons by keeping track
* of whether a button is pressed and refusing to pick a new current
* character while a button is pressed.
*/
int mask;
case Button1:
mask = Button1Mask;
break;
case Button2:
mask = Button2Mask;
break;
case Button3:
mask = Button3Mask;
break;
case Button4:
mask = Button4Mask;
break;
case Button5:
mask = Button5Mask;
break;
default:
mask = 0;
break;
}
repick = 1;
}
} else {
}
goto done;
} else {
}
}
}
if (repick) {
unsigned int oldState;
}
done:
}
/*
*--------------------------------------------------------------
*
* TkTextPickCurrent --
*
* Find the character containing the coordinates in an event
* and place the "current" mark on that character. If the
* "current" mark has moved then generate a fake leave event
* on the old current character and a fake enter event on the new
* current character.
*
* Results:
* None.
*
* Side effects:
* The current mark for textPtr may change. If it does,
* then the commands associated with character entry and leave
* could do just about anything. For example, the text widget
* might be deleted. It is up to the caller to protect itself
* with calls to Tcl_Preserve and Tcl_Release.
*
*--------------------------------------------------------------
*/
void
* current character. */
* mouse cursor. Must be EnterWindow,
* LeaveWindow, ButtonRelease, or
* MotionNotify. */
{
* compiler warning. */
/*
* If a button is down, then don't do anything at all; we'll be
* called again when all buttons are up, and we can repick then.
* This implements a form of mouse grabbing.
*/
/*
* Special case: the window is being entered or left because
* of a grab or ungrab. In this case, repick after all.
* Furthermore, clear BUTTON_DOWN to release the simulated
* grab.
*/
} else {
return;
}
}
/*
* Save information about this event in the widget in case we have
* to synthesize more enter and leave events later (e.g. because a
* character was deleted, causing a new character to be underneath
* the mouse cursor). Also translate MotionNotify events into
* EnterNotify events, since that's what gets reported to event
* handlers when the current character changes.
*/
} else {
}
}
/*
* Find the new current character, then find and sort all of the
* tags associated with it.
*/
} else {
newArrayPtr = NULL;
numNewTags = 0;
}
/*
* Resort the tags associated with the previous marked character
* (the priorities might have changed), then make a copy of the
* new tags, and compare the old tags to the copy, nullifying
* any tags that are present in both groups (i.e. the tags that
* haven't changed).
*/
if (numNewTags > 0) {
for (i = 0; i < textPtr->numCurTags; i++) {
for (j = 0; j < numNewTags; j++) {
copyArrayPtr[j] = NULL;
break;
}
}
}
}
/*
* Invoke the binding system with a LeaveNotify event for all of
* the tags that have gone away. We have to be careful here,
* because it's possible that the binding could do something
* (like calling tkwait) that eventually modifies
* textPtr->curTagArrayPtr. To avoid problems in situations like
* this, update curTagArrayPtr to its new value before invoking
* any bindings, and don't use it any more here.
*/
if (numOldTags != 0) {
/*
* Always use a detail of NotifyAncestor. Besides being
* consistent, this avoids problems where the binding code
* will discard NotifyInferior events.
*/
}
ckfree((char *) oldArrayPtr);
}
/*
* Reset the "current" mark (be careful to recompute its location,
* since it might have changed during an event binding). Then
* invoke the binding system with an EnterNotify event for all of
* the tags that have just appeared.
*/
if (numNewTags != 0) {
}
ckfree((char *) copyArrayPtr);
}
}