Tk Source Code

Artifact [a64dd62626]
Login

Artifact a64dd626264d05f6940111803cad6ad47693e5a5:

Attachment "selectbg_1.patch" to ticket [3469780fff] added by fvogelnew1 2012-01-05 19:34:47.
Index: doc/text.n
==================================================================
--- doc/text.n
+++ doc/text.n
@@ -514,10 +514,16 @@
 leave between the end of the line and the right edge of the window.
 \fIPixels\fR may have any of the standard forms for screen distances. This
 option is only used when wrapping is enabled. If a text line wraps, the right
 margin for each line on the display is determined by the first non-elided
 character of that display line.
+.TP
+\fB\-selectbackground \fIcolor\fR
+.
+\fIColor\fR specifies the background color to use for selected characters
+associated with the tag. It may have any of the forms accepted by
+\fBTk_GetColor\fR.
 .TP
 \fB\-spacing1 \fIpixels\fR
 .
 \fIPixels\fR specifies how much additional space should be left above each
 text line, using any of the standard forms for screen distances. If a line

Index: generic/tkText.h
==================================================================
--- generic/tkText.h
+++ generic/tkText.h
@@ -360,10 +360,12 @@
 				 * overstrikeString is non-NULL. */
     char *rMarginString;	/* -rmargin option string (malloc-ed). NULL
 				 * means option not specified. */
     int rMargin;		/* Right margin for text, in pixels. Only
 				 * valid if rMarginString is non-NULL. */
+    Tk_3DBorder selBorder;	/* Border and background for selected
+				 * characters. */
     char *spacing1String;	/* -spacing1 option string (malloc-ed). NULL
 				 * means option not specified. */
     int spacing1;		/* Extra spacing above first display line for
 				 * text line. Only valid if spacing1String is
 				 * non-NULL. */

Index: generic/tkTextDisp.c
==================================================================
--- generic/tkTextDisp.c
+++ generic/tkTextDisp.c
@@ -748,10 +748,11 @@
     register TkTextTag *tagPtr;
     StyleValues styleValues;
     TextStyle *stylePtr;
     Tcl_HashEntry *hPtr;
     int numTags, isNew, i;
+    int isSelected;
     XGCValues gcValues;
     unsigned long mask;
     /*
      * The variables below keep track of the highest-priority specification
      * that has occurred for each of the various fields of the StyleValues.
@@ -786,16 +787,25 @@
     styleValues.spacing3 = textPtr->spacing3;
     styleValues.tabArrayPtr = textPtr->tabArrayPtr;
     styleValues.tabStyle = textPtr->tabStyle;
     styleValues.wrapMode = textPtr->wrapMode;
     styleValues.elide = 0;
+    isSelected = 0;
+
+    for (i = 0 ; i < numTags; i++) {
+	tagPtr = tagPtrs[i];
+       	if (tagPtr == textPtr->selTagPtr) {
+            isSelected = 1;
+            break;
+	}
+    }
 
     for (i = 0 ; i < numTags; i++) {
 	Tk_3DBorder border;
 
 	tagPtr = tagPtrs[i];
-	border = tagPtr->border;
+        border = tagPtr->border;
 
 	/*
 	 * If this is the selection tag, and inactiveSelBorder is NULL (the
 	 * default on Windows), then we need to skip it if we don't have the
 	 * focus.
@@ -809,10 +819,14 @@
 #endif
 	    ) {
 		continue;
 	    }
 	    border = textPtr->inactiveSelBorder;
+	}
+
+	if ((isSelected) && (tagPtr->selBorder != NULL)) {
+            border = tagPtr->selBorder;
 	}
 
 	if ((border != NULL) && (tagPtr->priority > borderPrio)) {
 	    styleValues.border = border;
 	    borderPrio = tagPtr->priority;

Index: generic/tkTextTag.c
==================================================================
--- generic/tkTextTag.c
+++ generic/tkTextTag.c
@@ -68,10 +68,12 @@
 	TK_OPTION_NULL_OK, 0, 0},
     {TK_OPTION_STRING, "-relief", NULL, NULL,
 	NULL, -1, Tk_Offset(TkTextTag, reliefString), TK_OPTION_NULL_OK, 0, 0},
     {TK_OPTION_STRING, "-rmargin", NULL, NULL,
 	NULL, -1, Tk_Offset(TkTextTag, rMarginString), TK_OPTION_NULL_OK, 0,0},
+    {TK_OPTION_BORDER, "-selectbackground", NULL, NULL,
+	NULL, -1, Tk_Offset(TkTextTag, selBorder), TK_OPTION_NULL_OK, 0, 0},
     {TK_OPTION_STRING, "-spacing1", NULL, NULL,
 	NULL, -1, Tk_Offset(TkTextTag, spacing1String), TK_OPTION_NULL_OK,0,0},
     {TK_OPTION_STRING, "-spacing2", NULL, NULL,
 	NULL, -1, Tk_Offset(TkTextTag, spacing2String), TK_OPTION_NULL_OK,0,0},
     {TK_OPTION_STRING, "-spacing3", NULL, NULL,
@@ -491,10 +493,11 @@
 		    || (tagPtr->wrapMode != TEXT_WRAPMODE_NULL)) {
 		tagPtr->affectsDisplay = 1;
 		tagPtr->affectsDisplayGeometry = 1;
 	    }
 	    if ((tagPtr->border != NULL)
+		    || (tagPtr->selBorder != NULL)
 		    || (tagPtr->reliefString != NULL)
 		    || (tagPtr->bgStipple != None)
 		    || (tagPtr->fgColor != NULL)
 		    || (tagPtr->fgStipple != None)
 		    || (tagPtr->overstrikeString != NULL)
@@ -988,10 +991,11 @@
     tagPtr->offset = 0;
     tagPtr->overstrikeString = NULL;
     tagPtr->overstrike = 0;
     tagPtr->rMarginString = NULL;
     tagPtr->rMargin = 0;
+    tagPtr->selBorder = NULL;
     tagPtr->spacing1String = NULL;
     tagPtr->spacing1 = 0;
     tagPtr->spacing2String = NULL;
     tagPtr->spacing2 = 0;
     tagPtr->spacing3String = NULL;