Attachment "listboxJustify.patch" to
ticket [454303ff]
added by
dkf
2001-08-23 16:48:46.
Index: generic/tkListbox.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/generic/tkListbox.c,v
retrieving revision 1.21
diff -u -r1.21 tkListbox.c
--- generic/tkListbox.c 2001/07/03 06:16:19 1.21
+++ generic/tkListbox.c 2001/08/23 09:46:24
@@ -158,6 +158,7 @@
* to issue. Malloc'ed. */
int state; /* Listbox state. */
Pixmap gray; /* Pixmap for displaying disabled text. */
+ int justify; /* justification option */
int flags; /* Various flag bits: see below for
* definitions. */
} Listbox;
@@ -284,6 +285,9 @@
{TK_OPTION_STRING, "-listvariable", "listVariable", "Variable",
DEF_LISTBOX_LIST_VARIABLE, -1, Tk_Offset(Listbox, listVarName),
TK_OPTION_NULL_OK, 0, 0},
+ {TK_OPTION_JUSTIFY, "-justify", "justify", "Justify",
+ DEF_LISTBOX_JUSTIFY, -1, Tk_Offset(Listbox, justify),
+ TK_CONFIG_NULL_OK, 0, 0},
{TK_OPTION_END, (char *) NULL, (char *) NULL, (char *) NULL,
(char *) NULL, 0, -1, 0, 0, 0}
};
@@ -573,6 +577,7 @@
listPtr->state = STATE_NORMAL;
listPtr->gray = None;
listPtr->flags = 0;
+ listPtr->justify = TK_JUSTIFY_LEFT;
/*
* Keep a hold of the associated tkwin until we destroy the listbox,
@@ -2017,9 +2022,20 @@
/* Draw the actual text of this item */
Tk_GetFontMetrics(listPtr->tkfont, &fm);
y += fm.ascent + listPtr->selBorderWidth;
- x = listPtr->inset + listPtr->selBorderWidth - listPtr->xOffset;
Tcl_ListObjIndex(listPtr->interp, listPtr->listObj, i, &curElement);
stringRep = Tcl_GetStringFromObj(curElement, &stringLen);
+ if (listPtr->justify == TK_JUSTIFY_LEFT) {
+ x = listPtr->inset + listPtr->selBorderWidth - listPtr->xOffset;
+ } else {
+ int textWidth =
+ Tk_TextWidth(listPtr->tkfont, stringRep, stringLen);
+ if (listPtr->justify == TK_JUSTIFY_CENTER) {
+ x = listPtr->selBorderWidth - listPtr->xOffset +
+ (Tk_Width(tkwin) - textWidth) / 2;
+ } else {
+ x = Tk_Width(tkwin) - 2*listPtr->inset - textWidth;
+ }
+ }
Tk_DrawChars(listPtr->display, pixmap, gc, listPtr->tkfont,
stringRep, stringLen, x, y);
Index: mac/tkMacDefault.h
===================================================================
RCS file: /cvsroot/tktoolkit/tk/mac/tkMacDefault.h,v
retrieving revision 1.9
diff -u -r1.9 tkMacDefault.h
--- mac/tkMacDefault.h 2000/07/28 16:34:55 1.9
+++ mac/tkMacDefault.h 2001/08/23 09:46:25
@@ -212,6 +212,7 @@
#define DEF_LISTBOX_HIGHLIGHT_BG NORMAL_BG
#define DEF_LISTBOX_HIGHLIGHT BLACK
#define DEF_LISTBOX_HIGHLIGHT_WIDTH "0"
+#define DEF_LISTBOX_JUSTIFY "left"
#define DEF_LISTBOX_RELIEF "solid"
#define DEF_LISTBOX_SCROLL_COMMAND ""
#define DEF_LISTBOX_LIST_VARIABLE ""
Index: unix/tkUnixDefault.h
===================================================================
RCS file: /cvsroot/tktoolkit/tk/unix/tkUnixDefault.h,v
retrieving revision 1.9
diff -u -r1.9 tkUnixDefault.h
--- unix/tkUnixDefault.h 2000/07/28 16:34:55 1.9
+++ unix/tkUnixDefault.h 2001/08/23 09:46:25
@@ -207,6 +207,7 @@
#define DEF_LISTBOX_HIGHLIGHT_BG NORMAL_BG
#define DEF_LISTBOX_HIGHLIGHT BLACK
#define DEF_LISTBOX_HIGHLIGHT_WIDTH "1"
+#define DEF_LISTBOX_JUSTIFY "left"
#define DEF_LISTBOX_RELIEF "sunken"
#define DEF_LISTBOX_SCROLL_COMMAND ""
#define DEF_LISTBOX_LIST_VARIABLE ""
Index: win/tkWinDefault.h
===================================================================
RCS file: /cvsroot/tktoolkit/tk/win/tkWinDefault.h,v
retrieving revision 1.9
diff -u -r1.9 tkWinDefault.h
--- win/tkWinDefault.h 2000/07/28 16:34:56 1.9
+++ win/tkWinDefault.h 2001/08/23 09:46:25
@@ -212,6 +212,7 @@
#define DEF_LISTBOX_HIGHLIGHT_BG NORMAL_BG
#define DEF_LISTBOX_HIGHLIGHT HIGHLIGHT
#define DEF_LISTBOX_HIGHLIGHT_WIDTH "1"
+#define DEF_LISTBOX_JUSTIFY "left"
#define DEF_LISTBOX_RELIEF "sunken"
#define DEF_LISTBOX_SCROLL_COMMAND ""
#define DEF_LISTBOX_LIST_VARIABLE ""