@@ -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 ,
0 commit comments