summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfvogel <fvogelnew1@free.fr>2018-02-06 23:28:09 (GMT)
committerfvogel <fvogelnew1@free.fr>2018-02-06 23:28:09 (GMT)
commit522151de45f6a75c19e39af1e8530999c99ee2bf (patch)
tree9dc2a027de1a9f66b6a5516a1a570c3054889cb1
parent9502fe89d75c03f9bb6e407d6acc8ae2ff0114b6 (diff)
downloadtk-522151de45f6a75c19e39af1e8530999c99ee2bf.zip
tk-522151de45f6a75c19e39af1e8530999c99ee2bf.tar.gz
tk-522151de45f6a75c19e39af1e8530999c99ee2bf.tar.bz2
Change -empty* option names to -placeholder*. Changes provided by René Zaumseil
-rw-r--r--generic/tkEntry.c45
-rw-r--r--generic/tkEntry.h10
-rw-r--r--generic/ttk/ttkEntry.c34
-rw-r--r--tests/entry.test16
-rw-r--r--tests/ttk/entry.test37
5 files changed, 90 insertions, 52 deletions
diff --git a/generic/tkEntry.c b/generic/tkEntry.c
index a88d6f4..054da2f 100644
--- a/generic/tkEntry.c
+++ b/generic/tkEntry.c
@@ -56,7 +56,8 @@ enum validateType {
};
#define DEF_ENTRY_VALIDATE "none"
#define DEF_ENTRY_INVALIDCMD ""
-#define DEF_ENTRY_EMPTYTEXT ""
+#define DEF_ENTRY_PLACEHOLDERTEXT ""
+#define DEF_ENTRY_PLACEHOLDERFG "#b3b3b3"
/*
* Information used for Entry objv parsing.
@@ -82,10 +83,10 @@ static const Tk_OptionSpec entryOptSpec[] = {
{TK_OPTION_COLOR, "-disabledforeground", "disabledForeground",
"DisabledForeground", DEF_ENTRY_DISABLED_FG, -1,
Tk_Offset(Entry, dfgColorPtr), TK_OPTION_NULL_OK, 0, 0},
- {TK_OPTION_COLOR, "-emptyforeground", "emptyForeground", "EmptyForeground",
- "#b3b3b3", -1, Tk_Offset(Entry, emptyColorPtr), 0, 0, 0},
- {TK_OPTION_STRING, "-emptytext", "emptyText", "EmptyText",
- DEF_ENTRY_EMPTYTEXT, -1, Tk_Offset(Entry, emptyString),
+ {TK_OPTION_COLOR, "-placeholderforeground", "placeholderForeground", "PlaceholderForeground",
+ DEF_ENTRY_PLACEHOLDERFG, -1, Tk_Offset(Entry, placeholderColorPtr), 0, 0, 0},
+ {TK_OPTION_STRING, "-placeholdertext", "placeholderText", "PlaceholderText",
+ DEF_ENTRY_PLACEHOLDERTEXT, -1, Tk_Offset(Entry, placeholderString),
TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_BOOLEAN, "-exportselection", "exportSelection",
"ExportSelection", DEF_ENTRY_EXPORT_SELECTION, -1,
@@ -543,7 +544,7 @@ Tk_EntryObjCmd(
entryPtr->avgWidth = 1;
entryPtr->validate = VALIDATE_NONE;
- entryPtr->emptyGC = None;
+ entryPtr->placeholderGC = None;
/*
* Keep a hold of the associated tkwin until we destroy the entry,
* otherwise Tk might free it while we still need it.
@@ -1494,15 +1495,15 @@ EntryWorldChanged(
}
entryPtr->textGC = gc;
- if (entryPtr->emptyColorPtr != NULL) {
- gcValues.foreground = entryPtr->emptyColorPtr->pixel;
+ if (entryPtr->placeholderColorPtr != NULL) {
+ gcValues.foreground = entryPtr->placeholderColorPtr->pixel;
}
mask = GCForeground | GCFont | GCGraphicsExposures;
gc = Tk_GetGC(entryPtr->tkwin, mask, &gcValues);
- if (entryPtr->emptyGC != None) {
- Tk_FreeGC(entryPtr->display, entryPtr->emptyGC);
+ if (entryPtr->placeholderGC != None) {
+ Tk_FreeGC(entryPtr->display, entryPtr->placeholderGC);
}
- entryPtr->emptyGC = gc;
+ entryPtr->placeholderGC = gc;
if (entryPtr->selFgColorPtr != NULL) {
gcValues.foreground = entryPtr->selFgColorPtr->pixel;
@@ -1755,14 +1756,14 @@ DisplayEntry(
* selected portion on top of it.
*/
- if (entryPtr->numChars || entryPtr->emptyChars == 0) {
+ if (entryPtr->numChars || entryPtr->placeholderChars == 0) {
Tk_DrawTextLayout(entryPtr->display, pixmap, entryPtr->textGC,
entryPtr->textLayout, entryPtr->layoutX, entryPtr->layoutY,
entryPtr->leftIndex, entryPtr->numChars);
} else {
- Tk_DrawTextLayout(entryPtr->display, pixmap, entryPtr->emptyGC,
- entryPtr->emptyLayout, entryPtr->inset, entryPtr->layoutY,
- 0, entryPtr->emptyChars);
+ Tk_DrawTextLayout(entryPtr->display, pixmap, entryPtr->placeholderGC,
+ entryPtr->placeholderLayout, entryPtr->inset, entryPtr->layoutY,
+ 0, entryPtr->placeholderChars);
}
if (showSelection && (entryPtr->state != STATE_DISABLED)
@@ -1976,14 +1977,14 @@ EntryComputeGeometry(
*p = '\0';
}
- if (entryPtr->emptyString) {
- entryPtr->emptyChars = strlen(entryPtr->emptyString);
+ if (entryPtr->placeholderString) {
+ entryPtr->placeholderChars = strlen(entryPtr->placeholderString);
} else {
- entryPtr->emptyChars = 0;
+ entryPtr->placeholderChars = 0;
}
- Tk_FreeTextLayout(entryPtr->emptyLayout);
- entryPtr->emptyLayout = Tk_ComputeTextLayout(entryPtr->tkfont,
- entryPtr->emptyString, entryPtr->emptyChars, 0,
+ Tk_FreeTextLayout(entryPtr->placeholderLayout);
+ entryPtr->placeholderLayout = Tk_ComputeTextLayout(entryPtr->tkfont,
+ entryPtr->placeholderString, entryPtr->placeholderChars, 0,
entryPtr->justify, TK_IGNORE_NEWLINES, &totalLength, &height);
Tk_FreeTextLayout(entryPtr->textLayout);
@@ -3680,7 +3681,7 @@ Tk_SpinboxObjCmd(
sbPtr->bdRelief = TK_RELIEF_FLAT;
sbPtr->buRelief = TK_RELIEF_FLAT;
- entryPtr->emptyGC = None;
+ entryPtr->placeholderGC = None;
/*
* Keep a hold of the associated tkwin until we destroy the spinbox,
* otherwise Tk might free it while we still need it.
diff --git a/generic/tkEntry.h b/generic/tkEntry.h
index 5e8bb52..1ad2962 100644
--- a/generic/tkEntry.h
+++ b/generic/tkEntry.h
@@ -131,11 +131,11 @@ typedef struct {
/*
* Fields used in displaying help text if entry value is empty
*/
- Tk_TextLayout emptyLayout; /* Cached empty text layout information. */
- char *emptyString; /* String value of -emptytext */
- int emptyChars; /* Number of chars in -emptytext */
- XColor *emptyColorPtr; /* Color value of -emptyforeground */
- GC emptyGC; /* For drawing -emptytext text. */
+ Tk_TextLayout placeholderLayout;/* Cached placeholder text layout information. */
+ char *placeholderString; /* String value of -placeholdertext */
+ int placeholderChars; /* Number of chars in -placeholdertext */
+ XColor *placeholderColorPtr;/* Color value of -placeholderforeground */
+ GC placeholderGC; /* For drawing -placeholdertext text. */
/*
* Fields whose values are derived from the current values of the
diff --git a/generic/ttk/ttkEntry.c b/generic/ttk/ttkEntry.c
index 4a61240..9f27ef7 100644
--- a/generic/ttk/ttkEntry.c
+++ b/generic/ttk/ttkEntry.c
@@ -73,7 +73,7 @@ static const char *const validateReasonStrings[] = {
/* Style parameters:
*/
typedef struct {
- Tcl_Obj *emptyForegroundObj;/* Foreground color for empty text */
+ Tcl_Obj *placeholderForegroundObj;/* Foreground color for placeholder text */
Tcl_Obj *foregroundObj; /* Foreground color for normal text */
Tcl_Obj *backgroundObj; /* Entry widget background color */
Tcl_Obj *selBorderObj; /* Border and background for selection */
@@ -119,7 +119,7 @@ typedef struct {
Tcl_Obj *stateObj; /* Compatibility option -- see CheckStateObj */
- Tcl_Obj *emptyTextObj; /* Text to display for empty text */
+ Tcl_Obj *placeholderTextObj;/* Text to display for placeholder text */
/*
* Derived resources:
@@ -152,15 +152,15 @@ typedef struct {
*/
#define DEF_SELECT_BG "#000000"
#define DEF_SELECT_FG "#ffffff"
-#define DEF_EMPTY_FG "#b3b3b3"
+#define DEF_PLACEHOLDER_FG "#b3b3b3"
#define DEF_INSERT_BG "black"
#define DEF_ENTRY_WIDTH "20"
#define DEF_ENTRY_FONT "TkTextFont"
#define DEF_LIST_HEIGHT "10"
static Tk_OptionSpec EntryOptionSpecs[] = {
- {TK_OPTION_STRING, "-emptytext", "emptyText", "EmptyText",
- NULL, Tk_Offset(Entry, entry.emptyTextObj), -1,
+ {TK_OPTION_STRING, "-placeholdertext", "placeholderText", "PlaceholderText",
+ NULL, Tk_Offset(Entry, entry.placeholderTextObj), -1,
TK_OPTION_NULL_OK, 0, 0},
{TK_OPTION_BOOLEAN, "-exportselection", "exportSelection",
"ExportSelection", "1", -1, Tk_Offset(Entry, entry.exportSelection),
@@ -198,8 +198,8 @@ static Tk_OptionSpec EntryOptionSpecs[] = {
/* EntryStyleData options:
*/
- {TK_OPTION_COLOR, "-emptyforeground", "emptyForeground", "EmptyForeground",
- NULL, Tk_Offset(Entry, entry.styleData.emptyForegroundObj), -1,
+ {TK_OPTION_COLOR, "-placeholderforeground", "placeholderForeground", "PlaceholderForeground",
+ NULL, Tk_Offset(Entry, entry.styleData.placeholderForegroundObj), -1,
TK_OPTION_NULL_OK,0,0},
{TK_OPTION_COLOR, "-foreground", "textColor", "TextColor",
NULL, Tk_Offset(Entry, entry.styleData.foregroundObj), -1,
@@ -226,7 +226,7 @@ static void EntryInitStyleDefaults(EntryStyleData *es)
#define INIT(member, value) \
es->member = Tcl_NewStringObj(value, -1); \
Tcl_IncrRefCount(es->member);
- INIT(emptyForegroundObj, DEF_EMPTY_FG)
+ INIT(placeholderForegroundObj, DEF_PLACEHOLDER_FG)
INIT(foregroundObj, DEFAULT_FOREGROUND)
INIT(selBorderObj, DEF_SELECT_BG)
INIT(selForegroundObj, DEF_SELECT_FG)
@@ -238,7 +238,7 @@ static void EntryInitStyleDefaults(EntryStyleData *es)
static void EntryFreeStyleDefaults(EntryStyleData *es)
{
- Tcl_DecrRefCount(es->emptyForegroundObj);
+ Tcl_DecrRefCount(es->placeholderForegroundObj);
Tcl_DecrRefCount(es->foregroundObj);
Tcl_DecrRefCount(es->selBorderObj);
Tcl_DecrRefCount(es->selForegroundObj);
@@ -265,7 +265,7 @@ static void EntryInitStyleData(Entry *entryPtr, EntryStyleData *es)
# define INIT(member, name) \
if ((tmp=Ttk_QueryOption(entryPtr->core.layout,name,state))) \
es->member=tmp;
- INIT(emptyForegroundObj, "-emptyforeground");
+ INIT(placeholderForegroundObj, "-placeholderforeground");
INIT(foregroundObj, "-foreground");
INIT(selBorderObj, "-selectbackground")
INIT(selBorderWidthObj, "-selectborderwidth")
@@ -276,7 +276,7 @@ static void EntryInitStyleData(Entry *entryPtr, EntryStyleData *es)
/* Reacquire color & border resources from resource cache.
*/
- es->emptyForegroundObj = Ttk_UseColor(cache, tkwin, es->emptyForegroundObj);
+ es->placeholderForegroundObj = Ttk_UseColor(cache, tkwin, es->placeholderForegroundObj);
es->foregroundObj = Ttk_UseColor(cache, tkwin, es->foregroundObj);
es->selForegroundObj = Ttk_UseColor(cache, tkwin, es->selForegroundObj);
es->insertColorObj = Ttk_UseColor(cache, tkwin, es->insertColorObj);
@@ -321,14 +321,14 @@ static void EntryUpdateTextLayout(Entry *entryPtr)
int length;
char *text;
Tk_FreeTextLayout(entryPtr->entry.textLayout);
- if (entryPtr->entry.numChars>0 || entryPtr->entry.emptyTextObj==NULL) {
+ if (entryPtr->entry.numChars>0 || entryPtr->entry.placeholderTextObj==NULL) {
entryPtr->entry.textLayout = Tk_ComputeTextLayout(
Tk_GetFontFromObj(entryPtr->core.tkwin, entryPtr->entry.fontObj),
entryPtr->entry.displayString, entryPtr->entry.numChars,
0/*wraplength*/, entryPtr->entry.justify, TK_IGNORE_NEWLINES,
&entryPtr->entry.layoutWidth, &entryPtr->entry.layoutHeight);
} else {
- text = Tcl_GetStringFromObj(entryPtr->entry.emptyTextObj,&length);
+ text = Tcl_GetStringFromObj(entryPtr->entry.placeholderTextObj,&length);
entryPtr->entry.textLayout = Tk_ComputeTextLayout(
Tk_GetFontFromObj(entryPtr->core.tkwin, entryPtr->entry.fontObj),
text,length,
@@ -1293,11 +1293,11 @@ static void EntryDisplay(void *clientData, Drawable d)
/* Draw the text:
*/
if (*(entryPtr->entry.displayString) == '\0'
- && entryPtr->entry.emptyTextObj != NULL) {
- /* When no display text and -emptytext given */
- Tcl_GetStringFromObj(es.emptyForegroundObj,&rightIndex);
+ && entryPtr->entry.placeholderTextObj != NULL) {
+ /* When no display text and -placeholdertext given */
+ Tcl_GetStringFromObj(es.placeholderForegroundObj,&rightIndex);
if (++rightIndex > 1) {
- foregroundObj = es.emptyForegroundObj;
+ foregroundObj = es.placeholderForegroundObj;
} else {
foregroundObj = es.foregroundObj;
}
diff --git a/tests/entry.test b/tests/entry.test
index 82e4fd2..6a1a22f 100644
--- a/tests/entry.test
+++ b/tests/entry.test
@@ -627,20 +627,20 @@ test entry-1.58 {configuration option: "xscrollcommand" for entry} -setup {
destroy .e
} -result {Some command}
-test entry-1.59 {configuration option: "emptytext"} -setup {
+test entry-1.59 {configuration option: "-placeholdertext"} -setup {
pack [entry .e]
} -body {
- .e configure -emptytext {Some text}
- .e cget -emptytext
+ .e configure -placeholdertext {Some text}
+ .e cget -placeholdertext
} -cleanup {
destroy .e
} -result {Some text}
-test entry-1.60 {configuration option: "emptyforeground"} -setup {
+test entry-1.60 {configuration option: "-placeholderforeground"} -setup {
pack [entry .e]
} -body {
- .e configure -emptytext {Some text} -emptyforeground red
- .e cget -emptyforeground
+ .e configure -placeholdertext {Some text} -placeholderforeground red
+ .e cget -placeholderforeground
} -cleanup {
destroy .e
} -result {red}
@@ -3519,10 +3519,10 @@ test entry-24.1 {textvariable lives in a non-existing namespace} -setup {
destroy .e
} -result {can't trace "thisnsdoesntexist::myvar": parent namespace doesn't exist}
-test entry-25.1 {emptytext on/off shown} -setup {
+test entry-25.1 {-placeholdertext on/off shown} -setup {
pack [entry .e]
} -body {
- .e configure -emptytext {empty} -textvariable ::_e
+ .e configure -placeholdertext {placeholder} -textvariable ::_e
update; after 1000
set ::_e entry
update; after 1000
diff --git a/tests/ttk/entry.test b/tests/ttk/entry.test
index d95ef31..5cfdfee 100644
--- a/tests/ttk/entry.test
+++ b/tests/ttk/entry.test
@@ -280,4 +280,41 @@ test entry-9.1 "Index range invariants" -setup {
destroy .e
}
+test entry-10.1 {configuration option: "-placeholdertext"} -setup {
+ pack [entry .e]
+} -body {
+ .e configure -placeholdertext {Some text}
+ .e cget -placeholdertext
+} -cleanup {
+ destroy .e
+} -result {Some text}
+
+test entry-10.2 {style option: "-placeholderforeground"} -setup {
+ pack [entry .e]
+} -body {
+ ttk::style configure TEntry -foreground red
+ .e configure -placeholdertext {Some text}
+ update
+ ttk::style configure TEntry -foreground #b3b3b3
+ update
+} -cleanup {
+ destroy .e
+} -result {}
+
+test entry-10.3 {placeholdertext on/off shown} -setup {
+ pack [entry .e]
+} -body {
+ .e configure -placeholdertext {placeholder} -textvariable ::_e
+ update; after 1000
+ set ::_e entry
+ update; after 1000
+ set ::_e {}
+ update; after 1000
+ set ::_e entry
+ update; after 1000
+} -cleanup {
+ destroy .e
+ unset ::_e
+} -result {}
+
tcltest::cleanupTests