From 7eb4c1166891ec63b165278baa86e5f4bd23aca8 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Tue, 11 Feb 2014 14:56:03 +0000 Subject: [3f456a5bb9]: Patches for listbox right justify --- generic/tkListbox.c | 108 +++++++++++++++++++++++++++++++++++++++++++++-- library/demos/states.tcl | 9 ++++ macosx/tkMacOSXDefault.h | 1 + unix/tkUnixDefault.h | 1 + win/tkWinDefault.h | 1 + 5 files changed, 116 insertions(+), 4 deletions(-) diff --git a/generic/tkListbox.c b/generic/tkListbox.c index 437973a..22bb354 100644 --- a/generic/tkListbox.c +++ b/generic/tkListbox.c @@ -165,6 +165,8 @@ typedef struct { Pixmap gray; /* Pixmap for displaying disabled text. */ int flags; /* Various flag bits: see below for * definitions. */ + Tk_Justify justify; /* Justification */ + int oldMaxOffset; /* Used in scrolling for right/center justification */ } Listbox; /* @@ -308,6 +310,8 @@ static const Tk_OptionSpec optionSpecs[] = { {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), 0, 0, 0}, {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, -1, 0, 0, 0} }; @@ -435,6 +439,7 @@ static char * ListboxListVarProc(ClientData clientData, const char *name2, int flags); static void MigrateHashEntries(Tcl_HashTable *table, int first, int last, int offset); +static int GetMaxOffset(Listbox *listPtr); /* * The structure below defines button class behavior by means of procedures @@ -545,6 +550,8 @@ Tk_ListboxObjCmd( listPtr->cursor = None; listPtr->state = STATE_NORMAL; listPtr->gray = None; + listPtr->justify = TK_JUSTIFY_LEFT; + listPtr->oldMaxOffset = 0; /* * Keep a hold of the associated tkwin until we destroy the listbox, @@ -571,6 +578,13 @@ Tk_ListboxObjCmd( return TCL_ERROR; } + if (listPtr->justify == TK_JUSTIFY_RIGHT) { + listPtr->xOffset = GetMaxOffset(listPtr); + } else if (listPtr->justify == TK_JUSTIFY_CENTER) { + listPtr->xOffset = GetMaxOffset(listPtr) / 2; + listPtr->xOffset -= listPtr->xOffset % listPtr->xScrollUnit; + } + Tcl_SetObjResult(interp, TkNewWindowObj(listPtr->tkwin)); return TCL_OK; } @@ -1110,7 +1124,7 @@ ListboxBboxSubCmd( Tk_GetFontMetrics(listPtr->tkfont, &fm); pixelWidth = Tk_TextWidth(listPtr->tkfont, stringRep, stringLen); - x = listPtr->inset + listPtr->selBorderWidth - listPtr->xOffset; + x = listPtr->inset + listPtr->selBorderWidth - listPtr->xOffset; y = ((index - listPtr->topIndex)*listPtr->lineHeight) + listPtr->inset + listPtr->selBorderWidth; results[0] = Tcl_NewIntObj(x); @@ -1837,6 +1851,7 @@ DisplayListbox( * or right edge of the listbox is * off-screen. */ Pixmap pixmap; + int totalLength, height; listPtr->flags &= ~REDRAW_PENDING; if (listPtr->flags & LISTBOX_DELETED) { @@ -2055,12 +2070,22 @@ DisplayListbox( /* * Draw the actual text of this item. */ + 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); 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 if (listPtr->justify == TK_JUSTIFY_RIGHT) { + x = width - totalLength - listPtr->inset - listPtr->selBorderWidth - listPtr->xOffset + GetMaxOffset(listPtr) - 1; + } else { + x = (width + GetMaxOffset(listPtr))/2 - totalLength/2 - listPtr->xOffset; + } Tk_DrawChars(listPtr->display, pixmap, gc, listPtr->tkfont, stringRep, stringLen, x, y); @@ -2581,6 +2606,7 @@ ListboxEventProc( ClientData clientData, /* Information about window. */ XEvent *eventPtr) /* Information about event. */ { + int tmpOffset, tmpOffset2, maxOffset; Listbox *listPtr = clientData; if (eventPtr->type == Expose) { @@ -2612,6 +2638,53 @@ ListboxEventProc( } listPtr->flags |= UPDATE_V_SCROLLBAR|UPDATE_H_SCROLLBAR; ChangeListboxView(listPtr, listPtr->topIndex); + if (listPtr->justify == TK_JUSTIFY_RIGHT) { + maxOffset = GetMaxOffset(listPtr); + if (maxOffset != listPtr->oldMaxOffset && listPtr->oldMaxOffset > 0) { // window has shrunk + if (maxOffset > listPtr->oldMaxOffset) { + tmpOffset = maxOffset - listPtr->oldMaxOffset; + } else { + tmpOffset = listPtr->oldMaxOffset - maxOffset; + } + tmpOffset -= tmpOffset % listPtr->xScrollUnit; + if ((tmpOffset + listPtr->xOffset) > maxOffset) { + tmpOffset = maxOffset - listPtr->xOffset; + } + if (tmpOffset < 0) { + tmpOffset = 0; + } + listPtr->xOffset += tmpOffset; + } else { + listPtr->xOffset = maxOffset; + } + listPtr->oldMaxOffset = maxOffset; + } else if (listPtr->justify == TK_JUSTIFY_CENTER) { + maxOffset = GetMaxOffset(listPtr); + if (maxOffset != listPtr->oldMaxOffset && listPtr->oldMaxOffset > 0) { // window has shrunk + tmpOffset2 = maxOffset / 2; + if (maxOffset > listPtr->oldMaxOffset) { + tmpOffset = maxOffset/2 - listPtr->oldMaxOffset/2; + } else { + tmpOffset = listPtr->oldMaxOffset/2 - maxOffset/2; + } + tmpOffset -= tmpOffset % listPtr->xScrollUnit; + if ((tmpOffset + listPtr->xOffset) > maxOffset) { + tmpOffset = maxOffset - listPtr->xOffset; + } + if (tmpOffset < 0) { + tmpOffset = 0; + } + if (listPtr->xOffset < tmpOffset2) { + listPtr->xOffset += tmpOffset; + } else { + listPtr->xOffset -= tmpOffset; + } + } else { + listPtr->xOffset = maxOffset/2; + listPtr->xOffset -= listPtr->xOffset % listPtr->xScrollUnit; + } + listPtr->oldMaxOffset = maxOffset; + } ChangeListboxOffset(listPtr, listPtr->xOffset); /* @@ -3549,6 +3622,33 @@ MigrateHashEntries( } /* + *---------------------------------------------------------------------- + * + * GetMaxOffset -- + * + * Passing in a listbox pointer, returns the maximum offset for the box + * + * Results: + * Listbox's maxOffset + * + * Side effects: + * None + * + *---------------------------------------------------------------------- +*/ +static int GetMaxOffset(register Listbox *listPtr) +{ + int maxOffset; + + maxOffset = listPtr->maxWidth - (Tk_Width(listPtr->tkwin) - 2*listPtr->inset - 2*listPtr->selBorderWidth) + listPtr->xScrollUnit - 1; + if (maxOffset < 0) { + maxOffset = 0; + } + maxOffset -= maxOffset % listPtr->xScrollUnit; + + return maxOffset; +} +/* * Local Variables: * mode: c * c-basic-offset: 4 diff --git a/library/demos/states.tcl b/library/demos/states.tcl index e76540d..09d2718 100644 --- a/library/demos/states.tcl +++ b/library/demos/states.tcl @@ -19,6 +19,15 @@ positionWindow $w label $w.msg -font $font -wraplength 4i -justify left -text "A listbox containing the 50 states is displayed below, along with a scrollbar. You can scan the list either using the scrollbar or by scanning. To scan, press button 2 in the widget and drag up or down." pack $w.msg -side top +foreach c {Left Center Right} { + set lower [string tolower $c] + radiobutton $w.$lower -text $c -variable just \ + -relief flat -value $lower -anchor w \ + -command "$w.frame.list configure -justify \$just" \ + -tristatevalue "multi" + pack $w.$lower -side left -pady 2 -fill x +} + ## See Code / Dismiss buttons set btns [addSeeDismiss $w.buttons $w] pack $btns -side bottom -fill x diff --git a/macosx/tkMacOSXDefault.h b/macosx/tkMacOSXDefault.h index 8565cdb..903f5f9 100644 --- a/macosx/tkMacOSXDefault.h +++ b/macosx/tkMacOSXDefault.h @@ -262,6 +262,7 @@ #define DEF_LISTBOX_RELIEF "solid" #define DEF_LISTBOX_SCROLL_COMMAND "" #define DEF_LISTBOX_LIST_VARIABLE "" +#define DEF_LISTBOX_JUSTIFY "left" #define DEF_LISTBOX_SELECT_COLOR SELECT_BG #define DEF_LISTBOX_SELECT_MONO BLACK #define DEF_LISTBOX_SELECT_BD "0" diff --git a/unix/tkUnixDefault.h b/unix/tkUnixDefault.h index b922278..8768a2e 100644 --- a/unix/tkUnixDefault.h +++ b/unix/tkUnixDefault.h @@ -224,6 +224,7 @@ #define DEF_LISTBOX_RELIEF "sunken" #define DEF_LISTBOX_SCROLL_COMMAND "" #define DEF_LISTBOX_LIST_VARIABLE "" +#define DEF_LISTBOX_JUSTIFY "left" #define DEF_LISTBOX_SELECT_COLOR SELECT_BG #define DEF_LISTBOX_SELECT_MONO BLACK #define DEF_LISTBOX_SELECT_BD "0" diff --git a/win/tkWinDefault.h b/win/tkWinDefault.h index 11c3e6d..6d1a0c9 100644 --- a/win/tkWinDefault.h +++ b/win/tkWinDefault.h @@ -227,6 +227,7 @@ #define DEF_LISTBOX_RELIEF "sunken" #define DEF_LISTBOX_SCROLL_COMMAND "" #define DEF_LISTBOX_LIST_VARIABLE "" +#define DEF_LISTBOX_JUSTIFY "left" #define DEF_LISTBOX_SELECT_COLOR SELECT_BG #define DEF_LISTBOX_SELECT_MONO BLACK #define DEF_LISTBOX_SELECT_BD "0" -- cgit v0.12 From 5c01788dc22a4a2f8e6d9e943dc61a5b73b28291 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Tue, 11 Feb 2014 19:05:15 +0000 Subject: Adapt documentation and test-case --- doc/listbox.n | 7 ++++--- tests/listbox.test | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/doc/listbox.n b/doc/listbox.n index 4264823..1da40fd 100644 --- a/doc/listbox.n +++ b/doc/listbox.n @@ -17,9 +17,10 @@ listbox \- Create and manipulate 'listbox' item list widgets \-background \-borderwidth \-cursor \-disabledforeground \-exportselection \-font \-foreground \-highlightbackground \-highlightcolor -\-highlightthickness \-relief \-selectbackground -\-selectborderwidth \-selectforeground \-setgrid -\-takefocus \-xscrollcommand \-yscrollcommand +\-highlightthickness \-justify \-relief +\-selectbackground \-selectborderwidth \-selectforeground +\-setgrid \-takefocus \-xscrollcommand +\-yscrollcommand .SE .SH "WIDGET-SPECIFIC OPTIONS" .OP \-activestyle activeStyle ActiveStyle diff --git a/tests/listbox.test b/tests/listbox.test index e05d574..72b1cdf 100644 --- a/tests/listbox.test +++ b/tests/listbox.test @@ -455,7 +455,7 @@ test listbox-3.22 {ListboxWidgetCmd procedure, "cget" option} -body { } -result {0} test listbox-3.23 {ListboxWidgetCmd procedure, "configure" option} -body { llength [.l configure] -} -result {27} +} -result {28} test listbox-3.24 {ListboxWidgetCmd procedure, "configure" option} -body { .l configure -gorp } -returnCodes error -result {unknown option "-gorp"} -- cgit v0.12 From 5147bd27c61d07d5acfdd82046fccfdbb1aa38df Mon Sep 17 00:00:00 2001 From: fvogel Date: Mon, 11 Jan 2016 14:32:00 +0000 Subject: Improved patch formatting. No functional change --- generic/tkListbox.c | 70 ++++++++++++++++++++++++++++++------------------ macosx/tkMacOSXDefault.h | 2 +- unix/tkUnixDefault.h | 2 +- win/tkWinDefault.h | 2 +- 4 files changed, 47 insertions(+), 29 deletions(-) diff --git a/generic/tkListbox.c b/generic/tkListbox.c index f16218b..2929882 100644 --- a/generic/tkListbox.c +++ b/generic/tkListbox.c @@ -165,8 +165,9 @@ typedef struct { Pixmap gray; /* Pixmap for displaying disabled text. */ int flags; /* Various flag bits: see below for * definitions. */ - Tk_Justify justify; /* Justification */ - int oldMaxOffset; /* Used in scrolling for right/center justification */ + Tk_Justify justify; /* Justification. */ + int oldMaxOffset; /* Used in scrolling for right/center + * justification. */ } Listbox; /* @@ -277,6 +278,8 @@ static const Tk_OptionSpec optionSpecs[] = { {TK_OPTION_PIXELS, "-highlightthickness", "highlightThickness", "HighlightThickness", DEF_LISTBOX_HIGHLIGHT_WIDTH, -1, Tk_Offset(Listbox, highlightWidth), 0, 0, 0}, + {TK_OPTION_JUSTIFY, "-justify", "justify", "Justify", + DEF_LISTBOX_JUSTIFY, -1, Tk_Offset(Listbox, justify), 0, 0, 0}, {TK_OPTION_RELIEF, "-relief", "relief", "Relief", DEF_LISTBOX_RELIEF, -1, Tk_Offset(Listbox, relief), 0, 0, 0}, {TK_OPTION_BORDER, "-selectbackground", "selectBackground", "Foreground", @@ -310,8 +313,6 @@ static const Tk_OptionSpec optionSpecs[] = { {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), 0, 0, 0}, {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, -1, 0, 0, 0} }; @@ -440,7 +441,7 @@ static char * ListboxListVarProc(ClientData clientData, const char *name2, int flags); static void MigrateHashEntries(Tcl_HashTable *table, int first, int last, int offset); -static int GetMaxOffset(Listbox *listPtr); +static int GetMaxOffset(Listbox *listPtr); /* * The structure below defines button class behavior by means of procedures @@ -1125,7 +1126,7 @@ ListboxBboxSubCmd( Tk_GetFontMetrics(listPtr->tkfont, &fm); pixelWidth = Tk_TextWidth(listPtr->tkfont, stringRep, stringLen); - x = listPtr->inset + listPtr->selBorderWidth - listPtr->xOffset; + x = listPtr->inset + listPtr->selBorderWidth - listPtr->xOffset; y = ((index - listPtr->topIndex)*listPtr->lineHeight) + listPtr->inset + listPtr->selBorderWidth; results[0] = Tcl_NewIntObj(x); @@ -2071,23 +2072,27 @@ DisplayListbox( /* * Draw the actual text of this item. */ - 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); + + 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); Tk_GetFontMetrics(listPtr->tkfont, &fm); y += fm.ascent + listPtr->selBorderWidth; - if (listPtr->justify == TK_JUSTIFY_LEFT) { - 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; - } else { - x = (width + GetMaxOffset(listPtr))/2 - totalLength/2 - listPtr->xOffset; - } - Tk_DrawChars(listPtr->display, pixmap, gc, listPtr->tkfont, + if (listPtr->justify == TK_JUSTIFY_LEFT) { + 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; + } else { + x = (width + GetMaxOffset(listPtr))/2 - totalLength/2 - + listPtr->xOffset; + } + + Tk_DrawChars(listPtr->display, pixmap, gc, listPtr->tkfont, stringRep, stringLen, x, y); /* @@ -2641,7 +2646,12 @@ ListboxEventProc( ChangeListboxView(listPtr, listPtr->topIndex); if (listPtr->justify == TK_JUSTIFY_RIGHT) { maxOffset = GetMaxOffset(listPtr); - if (maxOffset != listPtr->oldMaxOffset && listPtr->oldMaxOffset > 0) { // window has shrunk + if (maxOffset != listPtr->oldMaxOffset && listPtr->oldMaxOffset > 0) { + + /* + * Window has shrunk. + */ + if (maxOffset > listPtr->oldMaxOffset) { tmpOffset = maxOffset - listPtr->oldMaxOffset; } else { @@ -2661,7 +2671,12 @@ ListboxEventProc( listPtr->oldMaxOffset = maxOffset; } else if (listPtr->justify == TK_JUSTIFY_CENTER) { maxOffset = GetMaxOffset(listPtr); - if (maxOffset != listPtr->oldMaxOffset && listPtr->oldMaxOffset > 0) { // window has shrunk + if (maxOffset != listPtr->oldMaxOffset && listPtr->oldMaxOffset > 0) { + + /* + * Window has shrunk. + */ + tmpOffset2 = maxOffset / 2; if (maxOffset > listPtr->oldMaxOffset) { tmpOffset = maxOffset/2 - listPtr->oldMaxOffset/2; @@ -3661,21 +3676,24 @@ MigrateHashEntries( * * GetMaxOffset -- * - * Passing in a listbox pointer, returns the maximum offset for the box + * Passing in a listbox pointer, returns the maximum offset for the box. * * Results: - * Listbox's maxOffset + * Listbox's maxOffset. * * Side effects: - * None + * None. * *---------------------------------------------------------------------- */ -static int GetMaxOffset(register Listbox *listPtr) +static int GetMaxOffset( + register Listbox *listPtr) { int maxOffset; - maxOffset = listPtr->maxWidth - (Tk_Width(listPtr->tkwin) - 2*listPtr->inset - 2*listPtr->selBorderWidth) + listPtr->xScrollUnit - 1; + maxOffset = listPtr->maxWidth - + (Tk_Width(listPtr->tkwin) - 2*listPtr->inset - + 2*listPtr->selBorderWidth) + listPtr->xScrollUnit - 1; if (maxOffset < 0) { maxOffset = 0; } diff --git a/macosx/tkMacOSXDefault.h b/macosx/tkMacOSXDefault.h index dc73188..65762b7 100644 --- a/macosx/tkMacOSXDefault.h +++ b/macosx/tkMacOSXDefault.h @@ -259,10 +259,10 @@ #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 "" -#define DEF_LISTBOX_JUSTIFY "left" #define DEF_LISTBOX_SELECT_COLOR SELECT_BG #define DEF_LISTBOX_SELECT_MONO BLACK #define DEF_LISTBOX_SELECT_BD "0" diff --git a/unix/tkUnixDefault.h b/unix/tkUnixDefault.h index ac7bc4d..2c3854d 100644 --- a/unix/tkUnixDefault.h +++ b/unix/tkUnixDefault.h @@ -221,10 +221,10 @@ #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 "" -#define DEF_LISTBOX_JUSTIFY "left" #define DEF_LISTBOX_SELECT_COLOR SELECT_BG #define DEF_LISTBOX_SELECT_MONO BLACK #define DEF_LISTBOX_SELECT_BD "0" diff --git a/win/tkWinDefault.h b/win/tkWinDefault.h index 29fe4ee..f389075 100644 --- a/win/tkWinDefault.h +++ b/win/tkWinDefault.h @@ -224,10 +224,10 @@ #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 "" -#define DEF_LISTBOX_JUSTIFY "left" #define DEF_LISTBOX_SELECT_COLOR SELECT_BG #define DEF_LISTBOX_SELECT_MONO BLACK #define DEF_LISTBOX_SELECT_BD "0" -- cgit v0.12 From 5de259d30a538e9ede43cea981bdf0002bb0601d Mon Sep 17 00:00:00 2001 From: fvogel Date: Mon, 11 Jan 2016 16:23:55 +0000 Subject: Polished listbox justification demo --- library/demos/states.tcl | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/library/demos/states.tcl b/library/demos/states.tcl index 41ce0bf..aeb3d5b 100644 --- a/library/demos/states.tcl +++ b/library/demos/states.tcl @@ -19,14 +19,16 @@ positionWindow $w label $w.msg -font $font -wraplength 4i -justify left -text "A listbox containing the 50 states is displayed below, along with a scrollbar. You can scan the list either using the scrollbar or by scanning. To scan, press button 2 in the widget and drag up or down." pack $w.msg -side top +labelframe $w.justif -text Justification foreach c {Left Center Right} { set lower [string tolower $c] - radiobutton $w.$lower -text $c -variable just \ - -relief flat -value $lower -anchor w \ - -command "$w.frame.list configure -justify \$just" \ - -tristatevalue "multi" - pack $w.$lower -side left -pady 2 -fill x + radiobutton $w.justif.$lower -text $c -variable just \ + -relief flat -value $lower -anchor w \ + -command "$w.frame.list configure -justify \$just" \ + -tristatevalue "multi" + pack $w.justif.$lower -side left -pady 2 -fill x } +pack $w.justif ## See Code / Dismiss buttons set btns [addSeeDismiss $w.buttons $w] -- cgit v0.12 From 2ab896442a6992390a79803686b3aa3abe266cc6 Mon Sep 17 00:00:00 2001 From: fvogel Date: Mon, 11 Jan 2016 18:00:11 +0000 Subject: Added some tests --- tests/listbox.test | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/listbox.test b/tests/listbox.test index 0519e93..effaad8 100644 --- a/tests/listbox.test +++ b/tests/listbox.test @@ -203,6 +203,21 @@ test listbox-1.31 {configuration options} -body { } -cleanup { .l configure -highlightthickness [lindex [.l configure -highlightthickness] 3] } -result {0 0} +test listbox-1.32.1 {configuration options} -setup { + set res {} +} -body { + .l configure -justify left + set res [list [lindex [.l configure -justify] 4] [.l cget -justify]] + .l configure -justify center + lappend res [lindex [.l configure -justify] 4] [.l cget -justify] + .l configure -justify right + lappend res [lindex [.l configure -justify] 4] [.l cget -justify] +} -cleanup { + .l configure -justify [lindex [.l configure -justify] 3] +} -result {left left center center right right} +test listbox-1.32.2 {configuration options} -body { + .l configure -justify bogus +} -returnCodes error -result {bad justification "bogus": must be left, right, or center} test listbox-1.33 {configuration options} -body { .l configure -relief groove list [lindex [.l configure -relief] 4] [.l cget -relief] -- cgit v0.12 From 9b0a5374a4e77d86b7a0e94ff46dceb6a413d246 Mon Sep 17 00:00:00 2001 From: fvogel Date: Tue, 12 Jan 2016 15:08:41 +0000 Subject: Added more tests --- tests/listbox.test | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/tests/listbox.test b/tests/listbox.test index effaad8..57cd974 100644 --- a/tests/listbox.test +++ b/tests/listbox.test @@ -456,6 +456,80 @@ test listbox-3.18 {ListboxWidgetCmd procedure, "bbox" option, partial last line} mkPartial list [.partial.l bbox 3] [.partial.l bbox 4] } -result {{5 56 24 14} {5 73 23 14}} +test listbox-3.18a {ListboxWidgetCmd procedure, "bbox" option, justified} -constraints { + fonts +} -setup { + destroy .top.l .top + unset -nocomplain res +} -body { + toplevel .top + listbox .top.l -justify left + .top.l insert end Item1 LongerItem2 MuchLongerItem3 + pack .top.l + update + lappend res [.top.l bbox 0] [.top.l bbox 1] [.top.l bbox 2] + .top.l configure -justify center + lappend res [.top.l bbox 0] [.top.l bbox 1] [.top.l bbox 2] + .top.l configure -justify right + lappend res [.top.l bbox 0] [.top.l bbox 1] [.top.l bbox 2] +} -cleanup { + destroy .top.l .top + unset -nocomplain res +} -result { + # + # Results to be defined when I get my hands on a platform featuring tcltest::testConstraints fonts == 1 + {TBD} {TBD} {TBD} {TBD} {TBD} {TBD} +} +test listbox-3.18b {ListboxWidgetCmd procedure, "bbox" option, justified, non-default borderwidth} -setup { + destroy .top.l .top + unset -nocomplain lres res +} -body { + toplevel .top + listbox .top.l -justify left -borderwidth 17 -highlightthickness 19 -selectborderwidth 22 + .top.l insert end Item1 LongerItem2 MuchLongerItem3 + .top.l selection set 1 + pack .top.l + update + lappend lres [.top.l bbox 0] [.top.l bbox 1] [.top.l bbox 2] + .top.l configure -justify center + lappend lres [.top.l bbox 0] [.top.l bbox 1] [.top.l bbox 2] + .top.l configure -justify right + lappend lres [.top.l bbox 0] [.top.l bbox 1] [.top.l bbox 2] + set res 1 + for {set i 0} {$i < [llength $lres]} {incr i 4} { + set res [expr {$res * [expr {[lindex $lres $i] >= 0}] }] + } + set res +} -cleanup { + destroy .top.l .top + unset -nocomplain lres res +} -result {1} +test listbox-3.18c {ListboxWidgetCmd procedure, "bbox" option, justified, selecting does not change offset} -setup { + destroy .top.l .top + unset -nocomplain bb1 bb2 +} -body { + toplevel .top + listbox .top.l -justify center + .top.l insert end Item1 Item2 Item3 + pack .top.l + update + set bb1 [.top.l bbox 1] + .top.l selection set 1 + update + set bb2 [.top.l bbox 1] + expr { + [lindex $bb1 0] == [lindex $bb2 0] && + [lindex $bb1 1] == [lindex $bb2 1] && + [lindex $bb1 2] == [lindex $bb2 2] && + [lindex $bb1 3] == [lindex $bb2 3] + } + # Note: the result of this test is relevant only if test listbox-3.18a + # succeeds first, otherwise the fact the present test listbox-3.18c + # passes does not mean it is OK +} -cleanup { + destroy .top.l .top + unset -nocomplain bb1 bb2 +} -result {1} test listbox-3.19 {ListboxWidgetCmd procedure, "cget" option} -body { .l cget } -returnCodes error -result {wrong # args: should be ".l cget option"} -- cgit v0.12 From 9976bb4ea9febe4dbdb963f7b5d81e4c71a21ba0 Mon Sep 17 00:00:00 2001 From: fvogel Date: Wed, 13 Jan 2016 07:16:53 +0000 Subject: Typo fixed --- generic/tkListbox.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generic/tkListbox.c b/generic/tkListbox.c index 2929882..7295677 100644 --- a/generic/tkListbox.c +++ b/generic/tkListbox.c @@ -90,7 +90,7 @@ typedef struct { * display. */ int topIndex; /* Index of top-most element visible in * window. */ - int fullLines; /* Number of lines that fit are completely + int fullLines; /* Number of lines that are completely * visible in window. There may be one * additional line at the bottom that is * partially visible. */ -- cgit v0.12 From cbe1741d686fd3de6be07ad51e091360d967b1ef Mon Sep 17 00:00:00 2001 From: fvogel Date: Wed, 13 Jan 2016 07:49:55 +0000 Subject: More typos fixed --- generic/tkListbox.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/generic/tkListbox.c b/generic/tkListbox.c index 7295677..50f1717 100644 --- a/generic/tkListbox.c +++ b/generic/tkListbox.c @@ -97,7 +97,7 @@ typedef struct { int partialLine; /* 0 means that the window holds exactly * fullLines lines. 1 means that there is one * additional line that is partially - * visble. */ + * visible. */ int setGrid; /* Non-zero means pass gridding information to * window manager. */ @@ -131,7 +131,7 @@ typedef struct { int active; /* Index of "active" element (the one that has * been selected by keyboard traversal). -1 * means none. */ - int activeStyle; /* style in which to draw the active element. + int activeStyle; /* Style in which to draw the active element. * One of: underline, none, dotbox */ /* @@ -200,7 +200,7 @@ typedef struct { * be updated. * GOT_FOCUS: Non-zero means this widget currently has the * input focus. - * MAXWIDTH_IS_STALE: Stored maxWidth may be out-of-date + * MAXWIDTH_IS_STALE: Stored maxWidth may be out-of-date. * LISTBOX_DELETED: This listbox has been effectively destroyed. */ @@ -318,7 +318,7 @@ static const Tk_OptionSpec optionSpecs[] = { /* * The itemAttrOptionSpecs table defines the valid configuration options for - * listbox items + * listbox items. */ static const Tk_OptionSpec itemAttrOptionSpecs[] = { @@ -345,7 +345,7 @@ static const Tk_OptionSpec itemAttrOptionSpecs[] = { }; /* - * The following tables define the listbox widget commands (and sub- commands) + * The following tables define the listbox widget commands (and sub-commands) * and map the indexes into the string tables into enumerated types used to * dispatch the listbox widget command. */ @@ -628,7 +628,7 @@ ListboxWidgetObjCmd( /* * Parse the command by looking up the second argument in the list of - * valid subcommand names + * valid subcommand names. */ result = Tcl_GetIndexFromObj(interp, objv[1], commandNames, @@ -2033,7 +2033,7 @@ DisplayListbox( } else { /* * If there is an item attributes record for this item, draw - * the background box and set the foreground color accordingly + * the background box and set the foreground color accordingly. */ if (entry != NULL) { @@ -2489,7 +2489,7 @@ ListboxDeleteSubCmd( /* * Check width of the element. We only have to check if widthChanged * has not already been set to 1, because we only need one maxWidth - * element to disappear for us to have to recompute the width + * element to disappear for us to have to recompute the width. */ if (widthChanged == 0) { @@ -2824,7 +2824,11 @@ GetListboxIndex( stringRep = Tcl_GetString(indexObj); if (stringRep[0] == '@') { - /* @x,y index */ + + /* + * @x,y index + */ + int y; const char *start; char *end; @@ -3554,7 +3558,7 @@ ListboxListVarProc( /* * If the list length has decreased, then we should clean up selection and - * attributes information for elements past the end of the new list + * attributes information for elements past the end of the new list. */ oldLength = listPtr->nElements; -- cgit v0.12 From 48ae923fc9c18de0e45d927b819cc756b6833aba Mon Sep 17 00:00:00 2001 From: fvogel Date: Sat, 16 Jan 2016 14:00:15 +0000 Subject: Addressed question 1 (see artifact [9d48a9c212] of ticket [3f456a5bb9]) --- generic/tkListbox.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/generic/tkListbox.c b/generic/tkListbox.c index 490f795..bea98ee 100644 --- a/generic/tkListbox.c +++ b/generic/tkListbox.c @@ -114,7 +114,8 @@ typedef struct { int xOffset; /* The left edge of each string in the listbox * is offset to the left by this many pixels * (0 means no offset, positive means there is - * an offset). */ + * an offset). This is x scrolling information + * is not linked to justification. */ /* * Information about what's selected or active, if any. -- cgit v0.12 From cc44a614a3a33b8007a980a64270832c67c629f2 Mon Sep 17 00:00:00 2001 From: fvogel Date: Sat, 16 Jan 2016 14:03:32 +0000 Subject: Addressed question 2 (see artifact [9d48a9c212] of ticket [3f456a5bb9]). This code arranges for the correct xview when creating the listbox with non-default justification. It is correctly placed in Tk_ListboxObjCmd. When changing justification later, i.e. in ConfigureListbox, there is no reason to change the xview, it would not be desired that the listbox xview jumps when configuring -justify. --- generic/tkListbox.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/generic/tkListbox.c b/generic/tkListbox.c index bea98ee..56e2c2f 100644 --- a/generic/tkListbox.c +++ b/generic/tkListbox.c @@ -581,6 +581,10 @@ Tk_ListboxObjCmd( return TCL_ERROR; } + /* + * Adjust startup x view according to the justify option. + */ + if (listPtr->justify == TK_JUSTIFY_RIGHT) { listPtr->xOffset = GetMaxOffset(listPtr); } else if (listPtr->justify == TK_JUSTIFY_CENTER) { -- cgit v0.12 From d48a10cb3142cfbefd0314439d877da5eb03b926 Mon Sep 17 00:00:00 2001 From: fvogel Date: Sat, 16 Jan 2016 14:16:00 +0000 Subject: Addressed issue A and question 6 (see artifact [9d48a9c212] of ticket [3f456a5bb9]). 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 From dfecb499abf1df3c0605d0058f454d8230221dd8 Mon Sep 17 00:00:00 2001 From: fvogel Date: Sat, 16 Jan 2016 14:20:40 +0000 Subject: Addressed issue B (see artifact [9d48a9c212] of ticket [3f456a5bb9]) --- generic/tkListbox.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/generic/tkListbox.c b/generic/tkListbox.c index a57650b..4f20d44 100644 --- a/generic/tkListbox.c +++ b/generic/tkListbox.c @@ -1096,6 +1096,7 @@ ListboxBboxSubCmd( Listbox *listPtr, /* Information about the listbox */ int index) /* Index of the element to get bbox info on */ { + register Tk_Window tkwin = listPtr->tkwin; int lastVisibleIndex; /* @@ -1131,7 +1132,15 @@ ListboxBboxSubCmd( Tk_GetFontMetrics(listPtr->tkfont, &fm); pixelWidth = Tk_TextWidth(listPtr->tkfont, stringRep, stringLen); - x = listPtr->inset + listPtr->selBorderWidth - listPtr->xOffset; + if (listPtr->justify == TK_JUSTIFY_LEFT) { + x = (listPtr->inset + listPtr->selBorderWidth) - listPtr->xOffset; + } else if (listPtr->justify == TK_JUSTIFY_RIGHT) { + x = Tk_Width(tkwin) - (listPtr->inset + listPtr->selBorderWidth) + - pixelWidth - listPtr->xOffset + GetMaxOffset(listPtr); + } else { + x = (Tk_Width(tkwin) - pixelWidth)/2 + - listPtr->xOffset + GetMaxOffset(listPtr)/2; + } y = ((index - listPtr->topIndex)*listPtr->lineHeight) + listPtr->inset + listPtr->selBorderWidth; results[0] = Tcl_NewIntObj(x); -- cgit v0.12 From e43c3c8be1a8b46419c5b4b8308a1dff03a803fc Mon Sep 17 00:00:00 2001 From: fvogel Date: Sat, 16 Jan 2016 15:43:00 +0000 Subject: Decided about test results for listbox-3.18a --- tests/listbox.test | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/listbox.test b/tests/listbox.test index fdad4c0..b62946d 100644 --- a/tests/listbox.test +++ b/tests/listbox.test @@ -476,11 +476,11 @@ test listbox-3.18a {ListboxWidgetCmd procedure, "bbox" option, justified} -const } -cleanup { destroy .top.l .top unset -nocomplain res -} -result { - # - # Results to be defined when I get my hands on a platform featuring tcltest::testConstraints fonts == 1 - {TBD} {TBD} {TBD} {TBD} {TBD} {TBD} -} +} -result [list \ + {5 5 34 14} {5 22 74 14} {5 39 106 14} \ + {58 5 34 14} {38 22 74 14} {22 39 106 14} \ + {111 5 34 14} {71 22 74 14} {39 39 106 14} \ +] test listbox-3.18b {ListboxWidgetCmd procedure, "bbox" option, justified, non-default borderwidth} -setup { destroy .top.l .top unset -nocomplain lres res -- cgit v0.12 From 24a1905f5c41cebbad36b04ef8c1f9327fe5a109 Mon Sep 17 00:00:00 2001 From: fvogel Date: Sat, 16 Jan 2016 15:45:54 +0000 Subject: Removed test listbox-3.18c since it is irrelevant (the rendering of the selected items is made in a code that depends on existence of a selection but this is untestable by bboxing since bbox is independent from the presence of a selection in the listbox) --- tests/listbox.test | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/tests/listbox.test b/tests/listbox.test index b62946d..812d1c2 100644 --- a/tests/listbox.test +++ b/tests/listbox.test @@ -505,32 +505,6 @@ test listbox-3.18b {ListboxWidgetCmd procedure, "bbox" option, justified, non-de destroy .top.l .top unset -nocomplain lres res } -result {1} -test listbox-3.18c {ListboxWidgetCmd procedure, "bbox" option, justified, selecting does not change offset} -setup { - destroy .top.l .top - unset -nocomplain bb1 bb2 -} -body { - toplevel .top - listbox .top.l -justify center - .top.l insert end Item1 Item2 Item3 - pack .top.l - update - set bb1 [.top.l bbox 1] - .top.l selection set 1 - update - set bb2 [.top.l bbox 1] - expr { - [lindex $bb1 0] == [lindex $bb2 0] && - [lindex $bb1 1] == [lindex $bb2 1] && - [lindex $bb1 2] == [lindex $bb2 2] && - [lindex $bb1 3] == [lindex $bb2 3] - } - # Note: the result of this test is relevant only if test listbox-3.18a - # succeeds first, otherwise the fact the present test listbox-3.18c - # passes does not mean it is OK -} -cleanup { - destroy .top.l .top - unset -nocomplain bb1 bb2 -} -result {1} test listbox-3.19 {ListboxWidgetCmd procedure, "cget" option} -body { .l cget } -returnCodes error -result {wrong # args: should be ".l cget option"} -- cgit v0.12 From 61a97384456cdf43006536d3436fa51ee3e9acff Mon Sep 17 00:00:00 2001 From: fvogel Date: Sun, 17 Jan 2016 20:40:01 +0000 Subject: Addressed questions 3 and 5 (see artifact [9d48a9c212] of ticket [3f456a5bb9]). It is not desirable to make the listbox xview jump on resizing. --- generic/tkListbox.c | 61 ----------------------------------------------------- 1 file changed, 61 deletions(-) diff --git a/generic/tkListbox.c b/generic/tkListbox.c index 4f20d44..9ff9d23 100644 --- a/generic/tkListbox.c +++ b/generic/tkListbox.c @@ -167,8 +167,6 @@ typedef struct { int flags; /* Various flag bits: see below for * definitions. */ Tk_Justify justify; /* Justification. */ - int oldMaxOffset; /* Used in scrolling for right/center - * justification. */ } Listbox; /* @@ -554,7 +552,6 @@ Tk_ListboxObjCmd( listPtr->state = STATE_NORMAL; listPtr->gray = None; listPtr->justify = TK_JUSTIFY_LEFT; - listPtr->oldMaxOffset = 0; /* * Keep a hold of the associated tkwin until we destroy the listbox, @@ -2623,7 +2620,6 @@ ListboxEventProc( ClientData clientData, /* Information about window. */ XEvent *eventPtr) /* Information about event. */ { - int tmpOffset, tmpOffset2, maxOffset; Listbox *listPtr = clientData; if (eventPtr->type == Expose) { @@ -2655,63 +2651,6 @@ ListboxEventProc( } listPtr->flags |= UPDATE_V_SCROLLBAR|UPDATE_H_SCROLLBAR; ChangeListboxView(listPtr, listPtr->topIndex); - if (listPtr->justify == TK_JUSTIFY_RIGHT) { - maxOffset = GetMaxOffset(listPtr); - if (maxOffset != listPtr->oldMaxOffset && listPtr->oldMaxOffset > 0) { - - /* - * Window has shrunk. - */ - - if (maxOffset > listPtr->oldMaxOffset) { - tmpOffset = maxOffset - listPtr->oldMaxOffset; - } else { - tmpOffset = listPtr->oldMaxOffset - maxOffset; - } - tmpOffset -= tmpOffset % listPtr->xScrollUnit; - if ((tmpOffset + listPtr->xOffset) > maxOffset) { - tmpOffset = maxOffset - listPtr->xOffset; - } - if (tmpOffset < 0) { - tmpOffset = 0; - } - listPtr->xOffset += tmpOffset; - } else { - listPtr->xOffset = maxOffset; - } - listPtr->oldMaxOffset = maxOffset; - } else if (listPtr->justify == TK_JUSTIFY_CENTER) { - maxOffset = GetMaxOffset(listPtr); - if (maxOffset != listPtr->oldMaxOffset && listPtr->oldMaxOffset > 0) { - - /* - * Window has shrunk. - */ - - tmpOffset2 = maxOffset / 2; - if (maxOffset > listPtr->oldMaxOffset) { - tmpOffset = maxOffset/2 - listPtr->oldMaxOffset/2; - } else { - tmpOffset = listPtr->oldMaxOffset/2 - maxOffset/2; - } - tmpOffset -= tmpOffset % listPtr->xScrollUnit; - if ((tmpOffset + listPtr->xOffset) > maxOffset) { - tmpOffset = maxOffset - listPtr->xOffset; - } - if (tmpOffset < 0) { - tmpOffset = 0; - } - if (listPtr->xOffset < tmpOffset2) { - listPtr->xOffset += tmpOffset; - } else { - listPtr->xOffset -= tmpOffset; - } - } else { - listPtr->xOffset = maxOffset/2; - listPtr->xOffset -= listPtr->xOffset % listPtr->xScrollUnit; - } - listPtr->oldMaxOffset = maxOffset; - } ChangeListboxOffset(listPtr, listPtr->xOffset); /* -- cgit v0.12 From f753eecfed15ad634f2a6b98c56a6cd1f0194beb Mon Sep 17 00:00:00 2001 From: fvogel Date: Sun, 17 Jan 2016 21:09:52 +0000 Subject: Addressed question 4 (see artifact [9d48a9c212] of ticket [3f456a5bb9]). --- generic/tkListbox.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/generic/tkListbox.c b/generic/tkListbox.c index 9ff9d23..e29c637 100644 --- a/generic/tkListbox.c +++ b/generic/tkListbox.c @@ -3630,7 +3630,8 @@ MigrateHashEntries( * * GetMaxOffset -- * - * Passing in a listbox pointer, returns the maximum offset for the box. + * Passing in a listbox pointer, returns the maximum offset for the box, + * i.e. the maximum possible horizontal scrolling value (in pixels). * * Results: * Listbox's maxOffset. @@ -3649,6 +3650,11 @@ static int GetMaxOffset( (Tk_Width(listPtr->tkwin) - 2*listPtr->inset - 2*listPtr->selBorderWidth) + listPtr->xScrollUnit - 1; if (maxOffset < 0) { + + /* + * Listbox is larger in width than its largest width item. + */ + maxOffset = 0; } maxOffset -= maxOffset % listPtr->xScrollUnit; -- cgit v0.12 From 53047ac807d37682c72abeb9a92fff3e41779108 Mon Sep 17 00:00:00 2001 From: fvogel Date: Mon, 18 Jan 2016 09:47:10 +0000 Subject: Fixed bug with the listbox justify patch: with large borders, when moving the horizontal scrollbar fully to the right the edge of the border could not be seen, one needed to push once on the right arrow of the scrollbar to see it. Test case: package require Tk destroy .top toplevel .top listbox .top.l -justify right -borderwidth 17 -highlightthickness 19 -selectborderwidth 22 scrollbar .top.hs -command ".top.l xview" -orient horizontal .top.l configure -xscrollcommand ".top.hs set" set huge [concat "START -" [string repeat "Huge Item... " 20] "- END"] .top.l insert end $huge pack .top.l -expand 1 -fill both pack .top.hs -expand 1 -fill x --- generic/tkListbox.c | 1 - 1 file changed, 1 deletion(-) diff --git a/generic/tkListbox.c b/generic/tkListbox.c index e29c637..ee6941e 100644 --- a/generic/tkListbox.c +++ b/generic/tkListbox.c @@ -3657,7 +3657,6 @@ static int GetMaxOffset( maxOffset = 0; } - maxOffset -= maxOffset % listPtr->xScrollUnit; return maxOffset; } -- cgit v0.12 From 85c13e1d28d4bac711f3b92737b501207e261280 Mon Sep 17 00:00:00 2001 From: fvogel Date: Mon, 18 Jan 2016 10:08:58 +0000 Subject: Use GetMaxOffset when possible to reduce code duplication. The change in ListboxScanTo is not exactly equivalent but I believe the previous version was a bug. --- generic/tkListbox.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/generic/tkListbox.c b/generic/tkListbox.c index ee6941e..795ec0f 100644 --- a/generic/tkListbox.c +++ b/generic/tkListbox.c @@ -2887,9 +2887,7 @@ ChangeListboxOffset( */ offset += listPtr->xScrollUnit / 2; - maxOffset = listPtr->maxWidth - (Tk_Width(listPtr->tkwin) - - 2*listPtr->inset - 2*listPtr->selBorderWidth) - + listPtr->xScrollUnit - 1; + maxOffset = GetMaxOffset(listPtr); if (offset > maxOffset) { offset = maxOffset; } @@ -2930,9 +2928,7 @@ ListboxScanTo( int newTopIndex, newOffset, maxIndex, maxOffset; maxIndex = listPtr->nElements - listPtr->fullLines; - maxOffset = listPtr->maxWidth + (listPtr->xScrollUnit - 1) - - (Tk_Width(listPtr->tkwin) - 2*listPtr->inset - - 2*listPtr->selBorderWidth - listPtr->xScrollUnit); + maxOffset = GetMaxOffset(listPtr); /* * Compute new top line for screen by amplifying the difference between -- cgit v0.12 From 94fd95f35c60eceaa87f6e666785e6a6d3fb5630 Mon Sep 17 00:00:00 2001 From: fvogel Date: Mon, 18 Jan 2016 10:19:24 +0000 Subject: Documented what listbox-3.18b intends to test. --- tests/listbox.test | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/listbox.test b/tests/listbox.test index 812d1c2..76a4349 100644 --- a/tests/listbox.test +++ b/tests/listbox.test @@ -485,6 +485,10 @@ test listbox-3.18b {ListboxWidgetCmd procedure, "bbox" option, justified, non-de destroy .top.l .top unset -nocomplain lres res } -body { + # This test checks whether all "x" values from bbox for different size + # items with different justification settings are all positive or zero + # This checks a bit the calculation of this x value with non-default + # borders widths of the listbox toplevel .top listbox .top.l -justify left -borderwidth 17 -highlightthickness 19 -selectborderwidth 22 .top.l insert end Item1 LongerItem2 MuchLongerItem3 -- cgit v0.12 From 60426c4ec3415ab57206d57f49f672f407b94a86 Mon Sep 17 00:00:00 2001 From: fvogel Date: Mon, 18 Jan 2016 18:17:30 +0000 Subject: Removed attempt of adjustment of the startup xview according to the -justify option. Anyway this does not work. --- generic/tkListbox.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/generic/tkListbox.c b/generic/tkListbox.c index 795ec0f..04dab6f 100644 --- a/generic/tkListbox.c +++ b/generic/tkListbox.c @@ -578,17 +578,6 @@ Tk_ListboxObjCmd( return TCL_ERROR; } - /* - * Adjust startup x view according to the justify option. - */ - - if (listPtr->justify == TK_JUSTIFY_RIGHT) { - listPtr->xOffset = GetMaxOffset(listPtr); - } else if (listPtr->justify == TK_JUSTIFY_CENTER) { - listPtr->xOffset = GetMaxOffset(listPtr) / 2; - listPtr->xOffset -= listPtr->xOffset % listPtr->xScrollUnit; - } - Tcl_SetObjResult(interp, TkNewWindowObj(listPtr->tkwin)); return TCL_OK; } -- cgit v0.12 From 65f1c08a6b543a6c25ad704beb200541fc7f6a94 Mon Sep 17 00:00:00 2001 From: fvogel Date: Mon, 18 Jan 2016 18:43:27 +0000 Subject: Reverted [5f396dacdc]. --- generic/tkListbox.c | 1 + tests/listbox.test | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/generic/tkListbox.c b/generic/tkListbox.c index 04dab6f..c7effdd 100644 --- a/generic/tkListbox.c +++ b/generic/tkListbox.c @@ -3642,6 +3642,7 @@ static int GetMaxOffset( maxOffset = 0; } + maxOffset -= maxOffset % listPtr->xScrollUnit; return maxOffset; } diff --git a/tests/listbox.test b/tests/listbox.test index 76a4349..40041de 100644 --- a/tests/listbox.test +++ b/tests/listbox.test @@ -509,6 +509,28 @@ test listbox-3.18b {ListboxWidgetCmd procedure, "bbox" option, justified, non-de destroy .top.l .top unset -nocomplain lres res } -result {1} +test listbox-3.18c {ListboxWidgetCmd procedure, "bbox" option, justified, with x scrolling} -setup { + destroy .top.l .top.hs .top + +} -body { +package req Tk +destroy .top.l .top.hs .top + toplevel .top + listbox .top.l -justify right -borderwidth 7 -highlightthickness 10 -selectborderwidth 20 + scrollbar .top.hs -command ".top.l xview" -orient horizontal + .top.l configure -xscrollcommand ".top.hs set" + set huge [concat "START -" [string repeat "Huge Item... " 20] "- END"] + .top.l insert end VeryVeryLongItem1 AnEvenMuchVeryVeryLongerItem2 $huge ShortItem3 + pack .top.l -expand 1 -fill both + pack .top.hs -expand 1 -fill x + update + + finish write this test case + +} -cleanup { + destroy .top.l .top.hs .top + +} -result {} test listbox-3.19 {ListboxWidgetCmd procedure, "cget" option} -body { .l cget } -returnCodes error -result {wrong # args: should be ".l cget option"} -- cgit v0.12 From eed41e54aa350fab52153895c9052ed38517e9fa Mon Sep 17 00:00:00 2001 From: fvogel Date: Mon, 18 Jan 2016 18:45:27 +0000 Subject: Removed unfinished test case committed by error in the previous commit. --- tests/listbox.test | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/tests/listbox.test b/tests/listbox.test index 40041de..76a4349 100644 --- a/tests/listbox.test +++ b/tests/listbox.test @@ -509,28 +509,6 @@ test listbox-3.18b {ListboxWidgetCmd procedure, "bbox" option, justified, non-de destroy .top.l .top unset -nocomplain lres res } -result {1} -test listbox-3.18c {ListboxWidgetCmd procedure, "bbox" option, justified, with x scrolling} -setup { - destroy .top.l .top.hs .top - -} -body { -package req Tk -destroy .top.l .top.hs .top - toplevel .top - listbox .top.l -justify right -borderwidth 7 -highlightthickness 10 -selectborderwidth 20 - scrollbar .top.hs -command ".top.l xview" -orient horizontal - .top.l configure -xscrollcommand ".top.hs set" - set huge [concat "START -" [string repeat "Huge Item... " 20] "- END"] - .top.l insert end VeryVeryLongItem1 AnEvenMuchVeryVeryLongerItem2 $huge ShortItem3 - pack .top.l -expand 1 -fill both - pack .top.hs -expand 1 -fill x - update - - finish write this test case - -} -cleanup { - destroy .top.l .top.hs .top - -} -result {} test listbox-3.19 {ListboxWidgetCmd procedure, "cget" option} -body { .l cget } -returnCodes error -result {wrong # args: should be ".l cget option"} -- cgit v0.12