Skip to content

Commit 3da8894

Browse files
author
jan.nijtmans
committed
Merge trunk
2 parents 4ff48b9 + e8745c5 commit 3da8894

28 files changed

+256
-267
lines changed

doc/listbox.n

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ listbox \- Create and manipulate 'listbox' item list widgets
1414
.SH SYNOPSIS
1515
\fBlistbox\fI pathName \fR?\fIoptions\fR?
1616
.SO
17-
\-background \-borderwidth \-cursor
18-
\-disabledforeground \-exportselection \-font
19-
\-foreground \-highlightbackground \-highlightcolor
20-
\-highlightthickness \-justify \-relief
21-
\-selectbackground \-selectborderwidth \-selectforeground
22-
\-setgrid \-takefocus \-xscrollcommand
23-
\-yscrollcommand
17+
\-background \-highlightbackground \-selectforeground
18+
\-borderwidth \-highlightcolor \-setgrid
19+
\-cursor \-highlightthickness \-takefocus
20+
\-disabledforeground \-justify \-xscrollcommand
21+
\-exportselection \-relief \-yscrollcommand
22+
\-font \-selectbackground
23+
\-foreground \-selectborderwidth
2424
.SE
2525
.SH "WIDGET-SPECIFIC OPTIONS"
2626
.OP \-activestyle activeStyle ActiveStyle
@@ -33,6 +33,23 @@ The default is \fBunderline\fR on Windows, and \fBdotbox\fR elsewhere.
3333
Specifies the desired height for the window, in lines.
3434
If zero or less, then the desired height for the window is made just
3535
large enough to hold all the elements in the listbox.
36+
.OP \-inactiveselectbackground inactiveSelectBackground Foreground
37+
Specifies the background color to use for the selection when the window does
38+
not have the input focus. The option's value may be an empty string or have
39+
any of the forms accepted by \fBTk_GetColor\fR. If empty then the value of the
40+
\fB-selectbackground\fR widget or item configuration option is used when the
41+
window does not have the focus. The default value depends on the windowing
42+
system: it is non-empty on \fBaqua\fR and \fBwin32\fR, and an empty string on
43+
\fBx11\fR.
44+
.OP \-inactiveselectforeground inactiveSelectForeground Background
45+
Specifies the foreground color to use for the selection when the window does
46+
not have the input focus. The option's value may be an empty string or have
47+
any of the forms accepted by \fBTk_GetColor\fR. This option is only relevant
48+
if the value of the \fB-inactiveselectbackground\fR option is non-empty, in
49+
which case, if the value of this option is an empty string then the value of
50+
the \fB-selectforeground\fR widget configuration option is used when the window
51+
does not have the focus. The default value depends on the windowing system: it
52+
is non-empty on \fBaqua\fR and \fBwin32\fR, and an empty string on \fBx11\fR.
3653
.OP \-listvariable listVariable Variable
3754
Specifies the name of a global variable. The value of the variable is a list to
3855
be displayed inside the widget; if the variable value changes then the

generic/tk.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ extern "C" {
9393
#if defined(__GNUC__) && !defined(__cplusplus)
9494
# pragma GCC diagnostic ignored "-Wc++-compat"
9595
#endif
96+
# define NeedWidePrototypes 1
9697
# include <X11/Xlib.h>
9798
# ifdef MAC_OSX_TK
9899
# include <X11/X.h>

generic/tkCmds.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,6 +1407,8 @@ WindowingsystemCmd(
14071407
windowingsystem = "win32";
14081408
#elif defined(MAC_OSX_TK)
14091409
windowingsystem = "aqua";
1410+
#elif defined(TK_USE_WAYLAND)
1411+
windowingsystem = "wayland";
14101412
#else
14111413
windowingsystem = "x11";
14121414
#endif

generic/tkEntry.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1991,7 +1991,7 @@ EntryComputeGeometry(
19911991
if (entryPtr->showCharObj != NULL) {
19921992
int ch;
19931993
char buf[6];
1994-
int size;
1994+
Tcl_Size size;
19951995

19961996
/*
19971997
* Normalize the special character so we can safely duplicate it in
@@ -2021,7 +2021,7 @@ EntryComputeGeometry(
20212021

20222022
Tk_FreeTextLayout(entryPtr->placeholderLayout);
20232023
if (entryPtr->placeholderObj) {
2024-
entryPtr->placeholderChars = strlen(Tcl_GetString(entryPtr->placeholderObj));
2024+
entryPtr->placeholderChars = Tcl_GetCharLength(entryPtr->placeholderObj);
20252025
entryPtr->placeholderLayout = Tk_ComputeTextLayout(entryPtr->tkfont,
20262026
Tcl_GetString(entryPtr->placeholderObj), entryPtr->placeholderChars, 0,
20272027
entryPtr->justify, TK_IGNORE_NEWLINES, &totalLength, NULL);

generic/tkListbox.c

Lines changed: 64 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,14 @@ typedef struct {
7777
GC textGC; /* For drawing normal text. */
7878
Tk_3DBorder selBorder; /* Borders and backgrounds for selected
7979
* elements. */
80+
Tk_3DBorder inactiveSelBorder;
81+
/* Borders and backgrounds for selected
82+
* elements when they don't have the focus. */
8083
Tcl_Obj *selBorderWidthObj; /* Width of border around selection. */
8184
XColor *selFgColorPtr; /* Foreground color for selected elements. */
85+
XColor *inactiveSelFgColorPtr;
86+
/* Foreground color for selected elements when
87+
* they don't have the focus. */
8288
GC selTextGC; /* For drawing selected text. */
8389
int width; /* Desired width of window, in characters. */
8490
int height; /* Desired height of window, in lines. */
@@ -269,8 +275,17 @@ static const Tk_OptionSpec optionSpecs[] = {
269275
{TK_OPTION_PIXELS, "-highlightthickness", "highlightThickness",
270276
"HighlightThickness", DEF_LISTBOX_HIGHLIGHT_WIDTH,
271277
offsetof(Listbox, highlightWidthObj), TCL_INDEX_NONE, 0, 0, 0},
278+
{TK_OPTION_BORDER, "-inactiveselectbackground", "inactiveSelectBackground",
279+
"Foreground", DEF_LISTBOX_INACTIVE_SELECT_COLOR,
280+
TCL_INDEX_NONE, offsetof(Listbox, inactiveSelBorder),
281+
TK_OPTION_NULL_OK, DEF_LISTBOX_SELECT_MONO, 0},
282+
{TK_OPTION_COLOR, "-inactiveselectforeground", "inactiveSelectForeground",
283+
"Background", DEF_LISTBOX_INACTIVE_SELECT_FG_COLOR,
284+
TCL_INDEX_NONE, offsetof(Listbox, inactiveSelFgColorPtr),
285+
TK_OPTION_NULL_OK, DEF_LISTBOX_SELECT_FG_MONO, 0},
272286
{TK_OPTION_JUSTIFY, "-justify", "justify", "Justify",
273-
DEF_LISTBOX_JUSTIFY, TCL_INDEX_NONE, offsetof(Listbox, justify), TK_OPTION_ENUM_VAR, 0, 0},
287+
DEF_LISTBOX_JUSTIFY, TCL_INDEX_NONE, offsetof(Listbox, justify),
288+
TK_OPTION_ENUM_VAR, 0, 0},
274289
{TK_OPTION_RELIEF, "-relief", "relief", "Relief",
275290
DEF_LISTBOX_RELIEF, TCL_INDEX_NONE, offsetof(Listbox, relief), 0, 0, 0},
276291
{TK_OPTION_BORDER, "-selectbackground", "selectBackground", "Foreground",
@@ -516,29 +531,31 @@ Tk_ListboxObjCmd(
516531
listPtr = (Listbox *)Tcl_Alloc(sizeof(Listbox));
517532
memset(listPtr, 0, sizeof(Listbox));
518533

519-
listPtr->tkwin = tkwin;
520-
listPtr->display = Tk_Display(tkwin);
521-
listPtr->interp = interp;
522-
listPtr->widgetCmd = Tcl_CreateObjCommand2(interp,
534+
listPtr->tkwin = tkwin;
535+
listPtr->display = Tk_Display(tkwin);
536+
listPtr->interp = interp;
537+
listPtr->widgetCmd = Tcl_CreateObjCommand2(interp,
523538
Tk_PathName(listPtr->tkwin), ListboxWidgetObjCmd, listPtr,
524539
ListboxCmdDeletedProc);
525-
listPtr->optionTable = optionTables->listboxOptionTable;
526-
listPtr->itemAttrOptionTable = optionTables->itemAttrOptionTable;
527-
listPtr->selection = (Tcl_HashTable *)Tcl_Alloc(sizeof(Tcl_HashTable));
540+
listPtr->optionTable = optionTables->listboxOptionTable;
541+
listPtr->itemAttrOptionTable = optionTables->itemAttrOptionTable;
542+
listPtr->selection = (Tcl_HashTable *)Tcl_Alloc(sizeof(Tcl_HashTable));
528543
Tcl_InitHashTable(listPtr->selection, TCL_ONE_WORD_KEYS);
529-
listPtr->itemAttrTable = (Tcl_HashTable *)Tcl_Alloc(sizeof(Tcl_HashTable));
544+
listPtr->itemAttrTable = (Tcl_HashTable *)Tcl_Alloc(sizeof(Tcl_HashTable));
530545
Tcl_InitHashTable(listPtr->itemAttrTable, TCL_ONE_WORD_KEYS);
531-
listPtr->relief = TK_RELIEF_RAISED;
532-
listPtr->textGC = NULL;
533-
listPtr->selFgColorPtr = NULL;
534-
listPtr->selTextGC = NULL;
535-
listPtr->fullLines = 1;
536-
listPtr->xScrollUnit = 1;
537-
listPtr->exportSelection = 1;
538-
listPtr->cursor = NULL;
539-
listPtr->state = STATE_NORMAL;
540-
listPtr->gray = None;
541-
listPtr->justify = TK_JUSTIFY_LEFT;
546+
listPtr->relief = TK_RELIEF_RAISED;
547+
listPtr->textGC = NULL;
548+
listPtr->inactiveSelBorder = NULL;
549+
listPtr->selFgColorPtr = NULL;
550+
listPtr->inactiveSelFgColorPtr = NULL;
551+
listPtr->selTextGC = NULL;
552+
listPtr->fullLines = 1;
553+
listPtr->xScrollUnit = 1;
554+
listPtr->exportSelection = 1;
555+
listPtr->cursor = NULL;
556+
listPtr->state = STATE_NORMAL;
557+
listPtr->gray = None;
558+
listPtr->justify = TK_JUSTIFY_LEFT;
542559

543560
/*
544561
* Keep a hold of the associated tkwin until we destroy the listbox,
@@ -1934,8 +1951,8 @@ DisplayListbox(
19341951

19351952
/*
19361953
* If the listbox is enabled, items may be drawn differently; they may
1937-
* be drawn selected, or they may have special foreground or
1938-
* background colors.
1954+
* be drawn selected, or they may have special foreground or background
1955+
* colors.
19391956
*/
19401957

19411958
if (listPtr->state & STATE_NORMAL) {
@@ -1944,37 +1961,42 @@ DisplayListbox(
19441961
* Selected items are drawn differently.
19451962
*/
19461963

1947-
gc = listPtr->selTextGC;
19481964
width = Tk_Width(tkwin) - 2 * listPtr->inset;
19491965
selectedBg = listPtr->selBorder;
1966+
gc = listPtr->selTextGC;
19501967

19511968
/*
1952-
* If there is attribute information for this item, adjust the
1953-
* drawing accordingly.
1969+
* If the widget doesn't have the focus and the value of the
1970+
* -inactiveselectbackground option is not empty then use this
1971+
* value. Otherwise, if there is attribute information for
1972+
* this item, then adjust the drawing accordingly.
19541973
*/
19551974

1956-
if (entry != NULL) {
1957-
attrs = (ItemAttr *)Tcl_GetHashValue(entry);
1975+
if (!(listPtr->flags & GOT_FOCUS) &&
1976+
listPtr->inactiveSelBorder) {
1977+
selectedBg = listPtr->inactiveSelBorder;
19581978

1959-
/*
1960-
* Default GC has the values from the widget at large.
1961-
*/
1962-
1963-
if (listPtr->selFgColorPtr) {
1964-
gcValues.foreground = listPtr->selFgColorPtr->pixel;
1965-
} else {
1966-
gcValues.foreground = listPtr->fgColorPtr->pixel;
1979+
if (listPtr->inactiveSelFgColorPtr) {
1980+
gcValues.foreground =
1981+
listPtr->inactiveSelFgColorPtr->pixel;
1982+
gcValues.font = Tk_FontId(listPtr->tkfont);
1983+
gcValues.graphics_exposures = False;
1984+
mask = GCForeground | GCFont | GCGraphicsExposures;
1985+
gc = Tk_GetGC(listPtr->tkwin, mask, &gcValues);
1986+
freeGC = 1;
19671987
}
1968-
gcValues.font = Tk_FontId(listPtr->tkfont);
1969-
gcValues.graphics_exposures = False;
1970-
mask = GCForeground | GCFont | GCGraphicsExposures;
1988+
} else if (entry != NULL) {
1989+
attrs = (ItemAttr *)Tcl_GetHashValue(entry);
19711990

19721991
if (attrs->selBorder != NULL) {
19731992
selectedBg = attrs->selBorder;
19741993
}
19751994

19761995
if (attrs->selFgColor != NULL) {
19771996
gcValues.foreground = attrs->selFgColor->pixel;
1997+
gcValues.font = Tk_FontId(listPtr->tkfont);
1998+
gcValues.graphics_exposures = False;
1999+
mask = GCForeground | GCFont | GCGraphicsExposures;
19782000
gc = Tk_GetGC(listPtr->tkwin, mask, &gcValues);
19792001
freeGC = 1;
19802002
}
@@ -2036,10 +2058,6 @@ DisplayListbox(
20362058

20372059
if (entry != NULL) {
20382060
attrs = (ItemAttr *)Tcl_GetHashValue(entry);
2039-
gcValues.foreground = listPtr->fgColorPtr->pixel;
2040-
gcValues.font = Tk_FontId(listPtr->tkfont);
2041-
gcValues.graphics_exposures = False;
2042-
mask = GCForeground | GCFont | GCGraphicsExposures;
20432061

20442062
/*
20452063
* If the item has its own background color, draw it now.
@@ -2059,6 +2077,9 @@ DisplayListbox(
20592077
if ((listPtr->state & STATE_NORMAL)
20602078
&& attrs->fgColor != NULL) {
20612079
gcValues.foreground = attrs->fgColor->pixel;
2080+
gcValues.font = Tk_FontId(listPtr->tkfont);
2081+
gcValues.graphics_exposures = False;
2082+
mask = GCForeground | GCFont | GCGraphicsExposures;
20622083
gc = Tk_GetGC(listPtr->tkwin, mask, &gcValues);
20632084
freeGC = 1;
20642085
}
@@ -2138,7 +2159,7 @@ DisplayListbox(
21382159
*/
21392160

21402161
Tk_GetPixelsFromObj(NULL, listPtr->tkwin, listPtr->borderWidthObj, &borderWidth);
2141-
Tk_GetPixelsFromObj(NULL, listPtr->tkwin, listPtr->highlightWidthObj, &highlightWidth);
2162+
Tk_GetPixelsFromObj(NULL, listPtr->tkwin, listPtr->highlightWidthObj, &highlightWidth);
21422163
Tk_Draw3DRectangle(tkwin, pixmap, listPtr->normalBorder,
21432164
highlightWidth, highlightWidth,
21442165
Tk_Width(tkwin) - 2 * highlightWidth,

generic/ttk/ttkEntry.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,6 @@ static char *EntryDisplayString(const char *showChar, int numChars)
319319
*/
320320
static void EntryUpdateTextLayout(Entry *entryPtr)
321321
{
322-
Tcl_Size length;
323-
char *text;
324322
Tk_FreeTextLayout(entryPtr->entry.textLayout);
325323
if ((entryPtr->entry.numChars != 0) || (entryPtr->entry.placeholderObj == NULL)) {
326324
entryPtr->entry.textLayout = Tk_ComputeTextLayout(
@@ -329,10 +327,10 @@ static void EntryUpdateTextLayout(Entry *entryPtr)
329327
0/*wraplength*/, entryPtr->entry.justify, TK_IGNORE_NEWLINES,
330328
&entryPtr->entry.layoutWidth, &entryPtr->entry.layoutHeight);
331329
} else {
332-
text = Tcl_GetStringFromObj(entryPtr->entry.placeholderObj, &length);
330+
Tcl_Size length = Tcl_GetCharLength(entryPtr->entry.placeholderObj);
333331
entryPtr->entry.textLayout = Tk_ComputeTextLayout(
334332
Tk_GetFontFromObj(entryPtr->core.tkwin, entryPtr->entry.fontObj),
335-
text, length,
333+
Tcl_GetString(entryPtr->entry.placeholderObj), length,
336334
0/*wraplength*/, entryPtr->entry.justify, TK_IGNORE_NEWLINES,
337335
&entryPtr->entry.layoutWidth, &entryPtr->entry.layoutHeight);
338336
}
@@ -1339,7 +1337,7 @@ static void EntryDisplay(void *clientData, Drawable d)
13391337
}
13401338
/* Use placeholder text width */
13411339
leftIndex = 0;
1342-
(void)Tcl_GetStringFromObj(entryPtr->entry.placeholderObj, &rightIndex);
1340+
rightIndex = Tcl_GetCharLength(entryPtr->entry.placeholderObj);
13431341
} else {
13441342
foregroundObj = es.foregroundObj;
13451343
}

generic/ttk/ttkLayout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Ttk_BoxContains(Ttk_Box box, int x, int y)
3131
&& box.y <= y && y < box.y + box.height;
3232
}
3333

34-
int
34+
bool
3535
TtkBoxEqual(Ttk_Box box1, Ttk_Box box2)
3636
{
3737
return box1.x == box2.x && box1.y == box2.y

generic/ttk/ttkTagSet.c

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -172,72 +172,68 @@ void Ttk_FreeTagSet(Ttk_TagSet tagset)
172172

173173
/* Ttk_TagSetContains -- test if tag set contains a tag.
174174
*/
175-
int Ttk_TagSetContains(Ttk_TagSet tagset, Ttk_Tag tag)
175+
bool Ttk_TagSetContains(Ttk_TagSet tagset, Ttk_Tag tag)
176176
{
177177
Tcl_Size i;
178178
for (i = 0; i < tagset->nTags; ++i) {
179179
if (tagset->tags[i] == tag) {
180-
return 1;
180+
return true;
181181
}
182182
}
183-
return 0;
183+
return false;
184184
}
185185

186186
/* Ttk_TagSetAdd -- add a tag to a tag set.
187187
*
188-
* Returns: 0 if tagset already contained tag,
189-
* 1 if tagset was modified.
188+
* Returns: false if tagset already contained tag,
189+
* true if tagset was modified.
190190
*/
191-
int Ttk_TagSetAdd(Ttk_TagSet tagset, Ttk_Tag tag)
191+
bool Ttk_TagSetAdd(Ttk_TagSet tagset, Ttk_Tag tag)
192192
{
193193
Tcl_Size i;
194194
for (i = 0; i < tagset->nTags; ++i) {
195195
if (tagset->tags[i] == tag) {
196-
return 0;
196+
return false;
197197
}
198198
}
199199
tagset->tags = (Ttk_Tag *)Tcl_Realloc(tagset->tags,
200200
(tagset->nTags+1)*sizeof(tagset->tags[0]));
201201
tagset->tags[tagset->nTags++] = tag;
202-
return 1;
202+
return true;
203203
}
204204

205205
/* Ttk_TagSetAddSet -- add a tag set to a tag set.
206206
*
207-
* Returns: 0 if tagset already contained tags,
208-
* 1 if tagset was modified.
209207
*/
210-
int Ttk_TagSetAddSet(Ttk_TagSet tagset, Ttk_TagSet tagsetFrom)
208+
void Ttk_TagSetAddSet(Ttk_TagSet tagset, Ttk_TagSet tagsetFrom)
211209
{
212210
Tcl_Size i, j, total, nTags = tagset->nTags;
213-
int result = 0, found;
211+
bool found;
214212
Ttk_Tag tag;
215213

216214
total = tagsetFrom->nTags + tagset->nTags;
217215
tagset->tags = (Ttk_Tag *)Tcl_Realloc(tagset->tags,
218216
(total)*sizeof(tagset->tags[0]));
219217
for (j = 0; j < tagsetFrom->nTags; ++j) {
220218
tag = tagsetFrom->tags[j];
221-
found = 0;
219+
found = false;
222220
for (i = 0; i < nTags; ++i) {
223221
if (tagset->tags[i] == tag) {
224-
found = 1;
222+
found = true;
225223
break;
226224
}
227225
}
228226
if (found) continue;
229227
tagset->tags[tagset->nTags++] = tag;
230-
result = 1;
231228
}
232-
return result;
233229
}
234230

235231
/* Ttk_TagSetRemove -- remove a tag from a tag set.
236232
*
237-
* Returns: 0 if tagset did not contain tag,
238-
* 1 if tagset was modified.
233+
* Returns: false if tagset did not contain tag,
234+
* true if tagset was modified.
239235
*/
240-
int Ttk_TagSetRemove(Ttk_TagSet tagset, Ttk_Tag tag)
236+
bool Ttk_TagSetRemove(Ttk_TagSet tagset, Ttk_Tag tag)
241237
{
242238
Tcl_Size i = 0, j = 0;
243239
while (i < tagset->nTags) {

0 commit comments

Comments
 (0)