Tk Source Code

Changes On Branch bug-8bee4b2009-alt
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Changes In Branch bug-8bee4b2009-alt Excluding Merge-Ins

This is equivalent to a diff from 79c6edba to 9287395c

2023-01-06
21:35
Fix [8bee4b2009]: progress bar no longer displays properly with certain styles. check-in: c0e5aa48 user: fvogel tags: trunk, main
2022-12-30
21:35
Refine progressbar-3.3 Closed-Leaf check-in: 9287395c user: fvogel tags: bug-8bee4b2009-alt
21:15
Simplify code by making better use of common parts between Text and cText elements. check-in: 2ff58248 user: fvogel tags: bug-8bee4b2009-alt
20:53
Another approach to fix [8bee4b2009]: Instead of the Text element used in other widgets, use a collapsing Text element. Test progressbar-3.3 passes. check-in: 9034028c user: fvogel tags: bug-8bee4b2009-alt
16:44
A workaround for [8bee4b2009]: the default font used for progressbars is of very small size. Test progressbar-3.3 now passes. Closed-Leaf check-in: fba99d26 user: fvogel tags: bug-8bee4b2009
16:41
Add (currently failing) test progressbar-3.3 demonstrating bug [8bee4b2009]. check-in: 79c6edba user: fvogel tags: bug-8bee4b2009
2022-12-29
22:56
Use some more point-expressions in stead of tk::ScaleNum check-in: bf9a2216 user: jan.nijtmans tags: trunk, main

Changes to generic/ttk/ttkLabel.c.

237
238
239
240
241
242
243











































244
245
246
247
248
249
250
static const Ttk_ElementSpec TextElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(TextElement),
    TextElementOptions,
    TextElementSize,
    TextElementDraw
};












































/*----------------------------------------------------------------------
 * +++ Image element.
 * Draws an image.
 */

typedef struct {







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
static const Ttk_ElementSpec TextElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(TextElement),
    TextElementOptions,
    TextElementSize,
    TextElementDraw
};

/*----------------------------------------------------------------------
 * +++ cText (collapsing text) element.
 *
 * This element is the same as the Text element, except its dimensions
 * are 0,0 when the text to display is "".
 */

static int cTextSetup(TextElement *text, Tk_Window tkwin)
{
    if (*Tcl_GetString(text->textObj) == '\0') {
        return 0;
    } else {
        return TextSetup(text, tkwin);
    }
}

static void cTextElementSize(
    void *dummy, void *elementRecord, Tk_Window tkwin,
    int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
{
    TextElement *text = (TextElement *)elementRecord;
    (void)dummy;
    (void)paddingPtr;

    if (!cTextSetup(text, tkwin))
	return;

    *heightPtr = text->height;
    *widthPtr = TextReqWidth(text);

    TextCleanup(text);

    return;
}

static const Ttk_ElementSpec cTextElementSpec = {
    TK_STYLE_VERSION_2,
    sizeof(TextElement),
    TextElementOptions,
    cTextElementSize,
    TextElementDraw
};

/*----------------------------------------------------------------------
 * +++ Image element.
 * Draws an image.
 */

typedef struct {
716
717
718
719
720
721
722

723
724
725
726

MODULE_SCOPE
void TtkLabel_Init(Tcl_Interp *interp)
{
    Ttk_Theme theme =  Ttk_GetDefaultTheme(interp);

    Ttk_RegisterElement(interp, theme, "text", &TextElementSpec, NULL);

    Ttk_RegisterElement(interp, theme, "image", &ImageElementSpec, NULL);
    Ttk_RegisterElement(interp, theme, "label", &LabelElementSpec, NULL);
}








>




759
760
761
762
763
764
765
766
767
768
769
770

MODULE_SCOPE
void TtkLabel_Init(Tcl_Interp *interp)
{
    Ttk_Theme theme =  Ttk_GetDefaultTheme(interp);

    Ttk_RegisterElement(interp, theme, "text", &TextElementSpec, NULL);
    Ttk_RegisterElement(interp, theme, "ctext", &cTextElementSpec, NULL);
    Ttk_RegisterElement(interp, theme, "image", &ImageElementSpec, NULL);
    Ttk_RegisterElement(interp, theme, "label", &LabelElementSpec, NULL);
}

Changes to generic/ttk/ttkProgress.c.

557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
    TTK_GROUP("Vertical.Progressbar.trough", TTK_FILL_BOTH,
	TTK_NODE("Vertical.Progressbar.pbar", TTK_PACK_BOTTOM|TTK_FILL_X))
TTK_END_LAYOUT

TTK_BEGIN_LAYOUT(HorizontalProgressbarLayout)
    TTK_GROUP("Horizontal.Progressbar.trough", TTK_FILL_BOTH,
	TTK_NODE("Horizontal.Progressbar.pbar", TTK_PACK_LEFT|TTK_FILL_Y)
	TTK_NODE("Horizontal.Progressbar.text", TTK_PACK_LEFT))
TTK_END_LAYOUT

/*
 * Initialization:
 */

MODULE_SCOPE







|







557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
    TTK_GROUP("Vertical.Progressbar.trough", TTK_FILL_BOTH,
	TTK_NODE("Vertical.Progressbar.pbar", TTK_PACK_BOTTOM|TTK_FILL_X))
TTK_END_LAYOUT

TTK_BEGIN_LAYOUT(HorizontalProgressbarLayout)
    TTK_GROUP("Horizontal.Progressbar.trough", TTK_FILL_BOTH,
	TTK_NODE("Horizontal.Progressbar.pbar", TTK_PACK_LEFT|TTK_FILL_Y)
	TTK_NODE("Horizontal.Progressbar.ctext", TTK_PACK_LEFT))
TTK_END_LAYOUT

/*
 * Initialization:
 */

MODULE_SCOPE

Changes to library/ttk/vistaTheme.tcl.

191
192
193
194
195
196
197
198
199
200
201
202
203
204
205

        # Progressbar
        ttk::style element create Horizontal.Progressbar.pbar vsapi \
            PROGRESS 3 {{} 1} -padding 8
        ttk::style layout Horizontal.TProgressbar {
            Horizontal.Progressbar.trough -sticky nswe -children {
                Horizontal.Progressbar.pbar -side left -sticky ns
                Horizontal.Progressbar.text -sticky nesw
            }
        }
        ttk::style element create Vertical.Progressbar.pbar vsapi \
            PROGRESS 3 {{} 1} -padding 8
        ttk::style layout Vertical.TProgressbar {
            Vertical.Progressbar.trough -sticky nswe -children {
                Vertical.Progressbar.pbar -side bottom -sticky we







|







191
192
193
194
195
196
197
198
199
200
201
202
203
204
205

        # Progressbar
        ttk::style element create Horizontal.Progressbar.pbar vsapi \
            PROGRESS 3 {{} 1} -padding 8
        ttk::style layout Horizontal.TProgressbar {
            Horizontal.Progressbar.trough -sticky nswe -children {
                Horizontal.Progressbar.pbar -side left -sticky ns
                Horizontal.Progressbar.ctext -sticky nesw
            }
        }
        ttk::style element create Vertical.Progressbar.pbar vsapi \
            PROGRESS 3 {{} 1} -padding 8
        ttk::style layout Vertical.TProgressbar {
            Vertical.Progressbar.trough -sticky nswe -children {
                Vertical.Progressbar.pbar -side bottom -sticky we

Changes to tests/ttk/progressbar.test.

119
120
121
122
123
124
125

126
127
128
129
130

131
132
133
134




135
136
137
138
139
140
141
142
143
144
145
146
    set res
} -cleanup {
    unset res thefont
    destroy .p
} -result {{-anchor e} {-foreground green} {-justify center} {-text {Cannot be seen}} {-wraplength 250}}

test progressbar-3.3 {horizontal progressbar height with no -text (TIP #442) specified - Bug [8bee4b2009]} -setup {

    set oldTheme [ttk::style theme use]
} -body {
    ttk::style theme use default
    set imga [image create photo -file [file join [file dirname [info script]] pb_image.svg] -format {svg -scale 0.8}]
    ::ttk::style element create Horizontal.Progressbar.pbar image $imga

    pack [ttk::progressbar .p -orient horizontal]
    .p step 25
    update
    expr {[winfo reqheight .p] == [image height $imga] + 2}




} -cleanup {
    destroy .p
    ttk::style theme use $oldTheme
    # there's no way I know to undo  '::ttk::style element create...'
} -result {1}

test progressbar-4.1 "style command" -body {
    ttk::progressbar .wh  ; # default is  -orient horizontal
    ttk::progressbar .wv -orient vertical
    list [.wh cget -style] [.wh style] [winfo class .wh]\
         [.wv cget -style] [.wv style] [winfo class .wv]
} -cleanup {







>





>
|


|
>
>
>
>




|







119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
    set res
} -cleanup {
    unset res thefont
    destroy .p
} -result {{-anchor e} {-foreground green} {-justify center} {-text {Cannot be seen}} {-wraplength 250}}

test progressbar-3.3 {horizontal progressbar height with no -text (TIP #442) specified - Bug [8bee4b2009]} -setup {
    set res {}
    set oldTheme [ttk::style theme use]
} -body {
    ttk::style theme use default
    set imga [image create photo -file [file join [file dirname [info script]] pb_image.svg] -format {svg -scale 0.8}]
    ::ttk::style element create Horizontal.Progressbar.pbar image $imga
    # -text "": progressbar height does not depend on font height
    pack [ttk::progressbar .p -orient horizontal -font {TkDefaultFont 24}]
    .p step 25
    update
    set res [expr {[winfo reqheight .p] == [image height $imga] + 2}]
    # -text "something": progressbar height adjusts to contain the font height
    .p configure -text Hello -font {TkDefaultFont 24}
    update
    lappend res [expr {[winfo reqheight .p] == [font metrics [.p cget -font] -linespace] + 2}]
} -cleanup {
    destroy .p
    ttk::style theme use $oldTheme
    # there's no way I know to undo  '::ttk::style element create...'
} -result {1 1}

test progressbar-4.1 "style command" -body {
    ttk::progressbar .wh  ; # default is  -orient horizontal
    ttk::progressbar .wv -orient vertical
    list [.wh cget -style] [.wh style] [winfo class .wh]\
         [.wv cget -style] [.wv style] [winfo class .wv]
} -cleanup {