Subject: Addressed issue A and question 6 (see artifact [9d48a9c212] of ticket [3f456a5bb9]).

From: fvogel <[email-masked]>
Date: Sat, 16 Jan 2016 14:16:00 +0000

Issue A is fixed. Test case:
  package req Tk
  listbox .l
  .l insert end M M M M M M M M M
  pack .l
  .l conf -just center   ; # or right
  .l conf -highlightthickness 40
  .l selection set 4

Regarding question 6, Tk_TextWidth is a bit lower level function in the API, which must be slightly beneficial regarding performance. Tk_TextWidth is therefore preferred.
---
 generic/tkListbox.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/generic/tkListbox.c b/generic/tkListbox.c
index 56e2c2f..a57650b 100644
--- a/generic/tkListbox.c
+++ b/generic/tkListbox.c
@@ -1857,7 +1857,7 @@ DisplayListbox(
 				 * or right edge of the listbox is
 				 * off-screen. */
     Pixmap pixmap;
-    int totalLength, height;
+    int textWidth;
 
     listPtr->flags &= ~REDRAW_PENDING;
     if (listPtr->flags & LISTBOX_DELETED) {
@@ -2079,21 +2079,19 @@ DisplayListbox(
 
         Tcl_ListObjIndex(listPtr->interp, listPtr->listObj, i, &curElement);
         stringRep = Tcl_GetStringFromObj(curElement, &stringLen);
-        Tk_ComputeTextLayout(listPtr->tkfont, stringRep, stringLen, 0,
-                listPtr->justify, TK_IGNORE_NEWLINES, &totalLength, &height);
+        textWidth = Tk_TextWidth(listPtr->tkfont, stringRep, stringLen);
 
 	Tk_GetFontMetrics(listPtr->tkfont, &fm);
 	y += fm.ascent + listPtr->selBorderWidth;
 
         if (listPtr->justify == TK_JUSTIFY_LEFT) {
-            x = listPtr->inset + listPtr->selBorderWidth - listPtr->xOffset;
+            x = (listPtr->inset + listPtr->selBorderWidth) - listPtr->xOffset;
         } else if (listPtr->justify == TK_JUSTIFY_RIGHT) {
-            x = width - totalLength - listPtr->inset -
-                    listPtr->selBorderWidth - listPtr->xOffset +
-                    GetMaxOffset(listPtr) - 1;
+            x = Tk_Width(tkwin) - (listPtr->inset + listPtr->selBorderWidth)
+                    - textWidth - listPtr->xOffset + GetMaxOffset(listPtr);
         } else {
-            x = (width + GetMaxOffset(listPtr))/2 - totalLength/2 -
-                    listPtr->xOffset;
+            x = (Tk_Width(tkwin) - textWidth)/2
+                    - listPtr->xOffset + GetMaxOffset(listPtr)/2;
         }
 
         Tk_DrawChars(listPtr->display, pixmap, gc, listPtr->tkfont,
-- 
cgit v0.12