summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog19
-rw-r--r--doc/entry.n24
-rw-r--r--generic/tkEntry.c83
-rw-r--r--mac/tkMacDefault.h4
-rw-r--r--tests/entry.test6
-rw-r--r--unix/tkUnixDefault.h4
-rw-r--r--win/tkWinDefault.h4
7 files changed, 93 insertions, 51 deletions
diff --git a/ChangeLog b/ChangeLog
index 2e7005e..19a205a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,24 @@
2000-05-17 Eric Melski <ericm@scriptics.com>
+ Overall change: Added "-readonlybackground" option for entries,
+ to enable a visual change when state goes to readonly.
+
+ * mac/tkMacDefault.h (DEF_ENTRY_READONLY_BG_COLOR,
+ DEF_ENTRY_READONLY_BG_COLOR):
+ * win/tkWinDefault.h (DEF_ENTRY_READONLY_BG_COLOR,
+ DEF_ENTRY_READONLY_BG_COLOR):
+ * unix/tkUnixDefault.h (DEF_ENTRY_READONLY_BG_COLOR,
+ DEF_ENTRY_READONLY_BG_COLOR): Added default values for entry
+ -readonlybackground option.
+
+ * generic/tkEntry.c: Added -readonlybackground option, cleaned up
+ excessive use of graphics contexts.
+
+ * tests/entry.test: Added configuration test for
+ -readonlybackground option.
+
+ * doc/entry.n: Added documentation for -readonlybackground option.
+
Overall change: changed implementation of "link" relief for
buttons. Instead of a new relief style (-relief link), there is a
new option, -overrelief, which if set is used when the mouse is
diff --git a/doc/entry.n b/doc/entry.n
index 474e2a2..12dade2 100644
--- a/doc/entry.n
+++ b/doc/entry.n
@@ -6,7 +6,7 @@
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
-'\" RCS: @(#) $Id: entry.n,v 1.5 2000/05/14 20:45:37 ericm Exp $
+'\" RCS: @(#) $Id: entry.n,v 1.6 2000/05/17 22:23:25 ericm Exp $
'\"
.so man.macros
.TH entry n 8.3 Tk "Tk Built-In Commands"
@@ -17,14 +17,15 @@ entry \- Create and manipulate entry widgets
.SH SYNOPSIS
\fBentry\fR \fIpathName \fR?\fIoptions\fR?
.SO
-\-background \-highlightthickness \-selectbackground
-\-borderwidth \-insertbackground \-selectborderwidth
-\-cursor \-insertborderwidth \-selectforeground
-\-exportselection \-insertofftime \-takefocus
-\-font \-insertontime \-textvariable
-\-foreground \-insertwidth \-xscrollcommand
-\-highlightbackground \-justify
-\-highlightcolor \-relief
+\-background \-borderwidth \-cursor
+\-exportselection \-font \-foreground
+\-highlightbackground \-highlightcolor \-highlightthickness
+\-insertbackground \-insertborderwidth \-insertofftime
+\-insertontime \-insertwidth \-justify
+\-relief \-selectbackground \-selectborderwidth
+\-selectforeground \-takefocus \-textvariable
+\-xscrollcommand
+
.SE
.SH "WIDGET-SPECIFIC OPTIONS"
.VS 8.4
@@ -42,6 +43,11 @@ Setting it to {} disables this feature (the default). The best use
of this option is to set it to \fIbell\fR. See \fBValidation\fR
below for more information.
.VE
+.VS 8.4
+.OP \-readonlybackground readonlyBackground ReadonlyBackground
+Specifies the background color to use when the entry is readonly. If
+this option is the empty string, the normal background color is used.
+.VE
.OP \-show show Show
If this option is specified, then the true contents of the entry
are not displayed in the window.
diff --git a/generic/tkEntry.c b/generic/tkEntry.c
index b14da83..2271c49 100644
--- a/generic/tkEntry.c
+++ b/generic/tkEntry.c
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkEntry.c,v 1.15 2000/05/14 20:45:37 ericm Exp $
+ * RCS: @(#) $Id: tkEntry.c,v 1.16 2000/05/17 22:23:25 ericm Exp $
*/
#include "tkInt.h"
@@ -75,6 +75,9 @@ typedef struct {
Tk_3DBorder disabledBorder; /* Used for drawing border around whole
* window in disabled state, plus used for
* background. */
+ Tk_3DBorder readonlyBorder; /* Used for drawing border around whole
+ * window in readonly state, plus used for
+ * background. */
int borderWidth; /* Width of 3-D border around window. */
Tk_Cursor cursor; /* Current cursor for window, or None. */
int exportSelection; /* Non-zero means tie internal entry selection
@@ -150,7 +153,6 @@ typedef struct {
/* Timer handler used to blink cursor on and
* off. */
GC textGC; /* For drawing normal text. */
- GC disabledTextGC; /* For drawing disabled text. */
GC selTextGC; /* For drawing selected text. */
GC highlightGC; /* For drawing traversal highlight. */
int avgWidth; /* Width of average character. */
@@ -310,6 +312,10 @@ static Tk_OptionSpec optionSpecs[] = {
(char *) NULL, 0, -1, 0, (ClientData) "-invalidcommand", 0},
{TK_OPTION_JUSTIFY, "-justify", "justify", "Justify",
DEF_ENTRY_JUSTIFY, -1, Tk_Offset(Entry, justify), 0, 0, 0},
+ {TK_OPTION_BORDER, "-readonlybackground", "readonlyBackground",
+ "ReadonlyBackground", DEF_ENTRY_READONLY_BG_COLOR, -1,
+ Tk_Offset(Entry, readonlyBorder), TK_OPTION_NULL_OK,
+ (ClientData) DEF_ENTRY_READONLY_BG_MONO, 0},
{TK_OPTION_RELIEF, "-relief", "relief", "Relief",
DEF_ENTRY_RELIEF, -1, Tk_Offset(Entry, relief),
0, 0, 0},
@@ -534,6 +540,7 @@ Tk_EntryObjCmd(clientData, interp, objc, objv)
entryPtr->normalBorder = NULL;
entryPtr->disabledBorder = NULL;
+ entryPtr->readonlyBorder = NULL;
entryPtr->borderWidth = 0;
entryPtr->cursor = None;
entryPtr->exportSelection = 1;
@@ -571,7 +578,6 @@ Tk_EntryObjCmd(clientData, interp, objc, objv)
entryPtr->leftIndex = 0;
entryPtr->insertBlinkHandler = (Tcl_TimerToken) NULL;
entryPtr->textGC = None;
- entryPtr->disabledTextGC = None;
entryPtr->selTextGC = None;
entryPtr->highlightGC = None;
entryPtr->avgWidth = 1;
@@ -1088,9 +1094,6 @@ DestroyEntry(memPtr)
if (entryPtr->textGC != None) {
Tk_FreeGC(entryPtr->display, entryPtr->textGC);
}
- if (entryPtr->disabledTextGC != None) {
- Tk_FreeGC(entryPtr->display, entryPtr->disabledTextGC);
- }
if (entryPtr->selTextGC != None) {
Tk_FreeGC(entryPtr->display, entryPtr->selTextGC);
}
@@ -1182,6 +1185,9 @@ ConfigureEntry(interp, entryPtr, objc, objv, flags)
if (entryPtr->state == STATE_DISABLED &&
entryPtr->disabledBorder != NULL) {
border = entryPtr->disabledBorder;
+ } else if (entryPtr->state == STATE_READONLY &&
+ entryPtr->readonlyBorder != NULL) {
+ border = entryPtr->readonlyBorder;
} else {
border = entryPtr->normalBorder;
}
@@ -1293,7 +1299,9 @@ EntryWorldChanged(instanceData)
GC gc = None;
unsigned long mask;
Entry *entryPtr;
-
+ Tk_3DBorder border;
+ XColor *colorPtr;
+
entryPtr = (Entry *) instanceData;
entryPtr->avgWidth = Tk_TextWidth(entryPtr->tkfont, "0", 1);
@@ -1301,14 +1309,32 @@ EntryWorldChanged(instanceData)
entryPtr->avgWidth = 1;
}
- if (entryPtr->state == STATE_DISABLED &&
- entryPtr->disabledBorder != NULL) {
- Tk_SetBackgroundFromBorder(entryPtr->tkwin, entryPtr->disabledBorder);
- } else if (entryPtr->normalBorder != NULL) {
- Tk_SetBackgroundFromBorder(entryPtr->tkwin, entryPtr->normalBorder);
+ /*
+ * Default background and foreground are from the normal state.
+ * In a disabled state, both of those may be overridden; in the readonly
+ * state, the background may be overridden.
+ */
+
+ border = entryPtr->normalBorder;
+ colorPtr = entryPtr->fgColorPtr;
+ switch (entryPtr->state) {
+ case STATE_DISABLED:
+ if (entryPtr->disabledBorder != NULL) {
+ border = entryPtr->disabledBorder;
+ }
+ if (entryPtr->dfgColorPtr != NULL) {
+ colorPtr = entryPtr->dfgColorPtr;
+ }
+ break;
+ case STATE_READONLY:
+ if (entryPtr->readonlyBorder != NULL) {
+ border = entryPtr->readonlyBorder;
+ }
+ break;
}
-
- gcValues.foreground = entryPtr->fgColorPtr->pixel;
+
+ Tk_SetBackgroundFromBorder(entryPtr->tkwin, border);
+ gcValues.foreground = colorPtr->pixel;
gcValues.font = Tk_FontId(entryPtr->tkfont);
gcValues.graphics_exposures = False;
mask = GCForeground | GCFont | GCGraphicsExposures;
@@ -1327,20 +1353,6 @@ EntryWorldChanged(instanceData)
}
entryPtr->selTextGC = gc;
- if (entryPtr->dfgColorPtr != NULL) {
- gcValues.foreground = entryPtr->dfgColorPtr->pixel;
- gcValues.font = Tk_FontId(entryPtr->tkfont);
- gcValues.graphics_exposures = False;
- mask = GCForeground | GCFont | GCGraphicsExposures;
- gc = Tk_GetGC(entryPtr->tkwin, mask, &gcValues);
- } else {
- gc = None;
- }
- if (entryPtr->disabledTextGC != None) {
- Tk_FreeGC(entryPtr->display, entryPtr->disabledTextGC);
- }
- entryPtr->disabledTextGC = gc;
-
/*
* Recompute the window's geometry and arrange for it to be
* redisplayed.
@@ -1378,7 +1390,6 @@ DisplayEntry(clientData)
Tk_FontMetrics fm;
Pixmap pixmap;
int showSelection;
- GC textGC;
Tk_3DBorder border;
entryPtr->flags &= ~REDRAW_PENDING;
@@ -1435,6 +1446,9 @@ DisplayEntry(clientData)
if (entryPtr->state == STATE_DISABLED &&
entryPtr->disabledBorder != NULL) {
border = entryPtr->disabledBorder;
+ } else if (entryPtr->state == STATE_READONLY &&
+ entryPtr->readonlyBorder != NULL) {
+ border = entryPtr->readonlyBorder;
} else {
border = entryPtr->normalBorder;
}
@@ -1498,17 +1512,12 @@ DisplayEntry(clientData)
* selected portion on top of it.
*/
- if (entryPtr->state == STATE_DISABLED && entryPtr->dfgColorPtr != NULL) {
- textGC = entryPtr->disabledTextGC;
- } else {
- textGC = entryPtr->textGC;
- }
- Tk_DrawTextLayout(entryPtr->display, pixmap, textGC,
+ Tk_DrawTextLayout(entryPtr->display, pixmap, entryPtr->textGC,
entryPtr->textLayout, entryPtr->layoutX, entryPtr->layoutY,
entryPtr->leftIndex, entryPtr->numChars);
if (showSelection && entryPtr->state != STATE_DISABLED
- && (entryPtr->selTextGC != textGC)
+ && (entryPtr->selTextGC != entryPtr->textGC)
&& (entryPtr->selectFirst < entryPtr->selectLast)) {
int selFirst;
@@ -1553,7 +1562,7 @@ DisplayEntry(clientData)
* and free up the pixmap.
*/
- XCopyArea(entryPtr->display, pixmap, Tk_WindowId(tkwin), textGC,
+ XCopyArea(entryPtr->display, pixmap, Tk_WindowId(tkwin), entryPtr->textGC,
0, 0, (unsigned) Tk_Width(tkwin), (unsigned) Tk_Height(tkwin),
0, 0);
Tk_FreePixmap(entryPtr->display, pixmap);
diff --git a/mac/tkMacDefault.h b/mac/tkMacDefault.h
index 42cfe76..e1ca127 100644
--- a/mac/tkMacDefault.h
+++ b/mac/tkMacDefault.h
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkMacDefault.h,v 1.7 2000/05/17 21:17:21 ericm Exp $
+ * RCS: @(#) $Id: tkMacDefault.h,v 1.8 2000/05/17 22:23:26 ericm Exp $
*/
#ifndef _TKMACDEFAULT
@@ -158,6 +158,8 @@
/* #define DEF_ENTRY_INSERT_WIDTH "2" */
#define DEF_ENTRY_INSERT_WIDTH "1"
#define DEF_ENTRY_JUSTIFY "left"
+#define DEF_ENTRY_READONLY_BG_COLOR NORMAL_BG
+#define DEF_ENTRY_READONLY_BG_MONO WHITE
/* #define DEF_ENTRY_RELIEF "sunken" */
#define DEF_ENTRY_RELIEF "solid"
#define DEF_ENTRY_SCROLL_COMMAND ""
diff --git a/tests/entry.test b/tests/entry.test
index 10178da..a44d1d4 100644
--- a/tests/entry.test
+++ b/tests/entry.test
@@ -6,7 +6,7 @@
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.
#
-# RCS: @(#) $Id: entry.test,v 1.8 2000/05/14 20:45:38 ericm Exp $
+# RCS: @(#) $Id: entry.test,v 1.9 2000/05/17 22:23:26 ericm Exp $
if {[lsearch [namespace children] ::tcltest] == -1} {
source [file join [pwd] [file dirname [info script]] defs.tcl]
@@ -79,6 +79,8 @@ foreach test {
{-insertofftime 100 100 3.2 {expected integer but got "3.2"}}
{-insertontime 100 100 3.2 {expected integer but got "3.2"}}
{-justify right right bogus {bad justification "bogus": must be left, right, or center}}
+ {-readonlybackground green green non-existent
+ {unknown color name "non-existent"}}
{-relief groove groove 1.5 {bad relief "1.5": must be flat, groove, raised, ridge, solid, or sunken}}
{-selectbackground #110022 #110022 bogus {unknown color name "bogus"}}
{-selectborderwidth 1.3 1 badValue {bad screen distance "badValue"}}
@@ -196,7 +198,7 @@ test entry-3.14 {EntryWidgetCmd procedure, "cget" widget command} {
} {4}
test entry-3.15 {EntryWidgetCmd procedure, "configure" widget command} {
llength [.e configure]
-} {35}
+} {36}
test entry-3.16 {EntryWidgetCmd procedure, "configure" widget command} {
list [catch {.e configure -foo} msg] $msg
} {1 {unknown option "-foo"}}
diff --git a/unix/tkUnixDefault.h b/unix/tkUnixDefault.h
index 312e579..eb81ff8 100644
--- a/unix/tkUnixDefault.h
+++ b/unix/tkUnixDefault.h
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkUnixDefault.h,v 1.7 2000/05/17 21:17:22 ericm Exp $
+ * RCS: @(#) $Id: tkUnixDefault.h,v 1.8 2000/05/17 22:23:26 ericm Exp $
*/
#ifndef _TKUNIXDEFAULT
@@ -153,6 +153,8 @@
#define DEF_ENTRY_INSERT_ON_TIME "600"
#define DEF_ENTRY_INSERT_WIDTH "2"
#define DEF_ENTRY_JUSTIFY "left"
+#define DEF_ENTRY_READONLY_BG_COLOR NORMAL_BG
+#define DEF_ENTRY_READONLY_BG_MONO WHITE
#define DEF_ENTRY_RELIEF "sunken"
#define DEF_ENTRY_SCROLL_COMMAND ""
#define DEF_ENTRY_SELECT_COLOR SELECT_BG
diff --git a/win/tkWinDefault.h b/win/tkWinDefault.h
index 1c59512..c7cf285 100644
--- a/win/tkWinDefault.h
+++ b/win/tkWinDefault.h
@@ -9,7 +9,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkWinDefault.h,v 1.7 2000/05/17 21:17:23 ericm Exp $
+ * RCS: @(#) $Id: tkWinDefault.h,v 1.8 2000/05/17 22:23:26 ericm Exp $
*/
#ifndef _TKWINDEFAULT
@@ -159,6 +159,8 @@
#define DEF_ENTRY_INSERT_ON_TIME "600"
#define DEF_ENTRY_INSERT_WIDTH "2"
#define DEF_ENTRY_JUSTIFY "left"
+#define DEF_ENTRY_READONLY_BG_COLOR "SystemButtonFace"
+#define DEF_ENTRY_READONLY_BG_MONO WHITE
#define DEF_ENTRY_RELIEF "sunken"
#define DEF_ENTRY_SCROLL_COMMAND ""
#define DEF_ENTRY_SELECT_COLOR SELECT_BG