Tk Source Code

Check-in [d1a4f177]
Login

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

Overview
Comment:Fix the underlying problem with empty menubuttons on the mac, rather than the symptom.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | bug-70e531918e
Files: files | file ages | folders
SHA3-256:d1a4f1775670c2176ea6e365ec62d6981315ba9c87148fc76e056f263aed3428
User & Date: culler 2019-01-14 13:57:38
Context
2019-01-15
14:00
Use TkGetMenuIndex to parse the index argument to the post command. check-in: 31984285 user: culler tags: bug-70e531918e
2019-01-14
13:57
Fix the underlying problem with empty menubuttons on the mac, rather than the symptom. check-in: d1a4f177 user: culler tags: bug-70e531918e
2019-01-13
19:24
Deal with empty menubuttons on the mac. check-in: 0bf6de05 user: culler tags: bug-70e531918e
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to macosx/tkMacOSXMenubutton.c.

106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
...
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
...
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
...
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
...
605
606
607
608
609
610
611
612

613
614

615
616
617
618
619
620
621
...
744
745
746
747
748
749
750
751



752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
...
808
809
810
811
812
813
814
815


816
817

818
819
820
821
822
823
824
 * explicit width for the button.  Apple also recommends using the same width
 * for all Pop-Up Buttons in a given window.
 */

#define LEFT_INSET 8
#define RIGHT_INSET 28
#define MIN_HEIGHT 22

 
/*
 *----------------------------------------------------------------------
 *
 * TkpCreateMenuButton  --
 *
 *	Allocate a new TkMenuButton structure.
................................................................................
        Tk_SizeOfImage(butPtr->image, &width, &height);
        haveImage = 1;
    } else if (butPtr->bitmap != None) {
        Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height);
        haveImage = 1;
    }

    /*
     * Mac menubuttons do not display correctly with no image and empty text.
     */

    if (haveImage == 0 && strlen(butPtr->text) == 0) {
	ckfree(butPtr->text);
	butPtr->text = ckalloc(2);
	strcpy(butPtr->text, " ");
    }
    
    if (haveImage == 0 || butPtr->compound != COMPOUND_NONE) {
        Tk_FreeTextLayout(butPtr->textLayout);
        butPtr->textLayout = Tk_ComputeTextLayout(butPtr->tkfont,
                butPtr->text, -1, butPtr->wrapLength,
                butPtr->justify, 0, &butPtr->textWidth, &butPtr->textHeight);

        txtWidth = butPtr->textWidth;
        txtHeight = butPtr->textHeight;
        avgWidth = Tk_TextWidth(butPtr->tkfont, "0", 1);
        Tk_GetFontMetrics(butPtr->tkfont, &fm);
    }

    /*
................................................................................
            if (butPtr->height > 0) {
                height = butPtr->height * fm.linespace + 2*butPtr->padY;
            }
        }
    }
    
    butPtr->inset = highlightWidth + butPtr->borderWidth;
    width  += LEFT_INSET + RIGHT_INSET + 2*butPtr->inset;
	height += 2*butPtr->inset;
    height = height < MIN_HEIGHT ? MIN_HEIGHT : height;
    Tk_GeometryRequest(butPtr->tkwin, width, height);
    Tk_SetInternalBorder(butPtr->tkwin, butPtr->inset);
}
 
/*
 *----------------------------------------------------------------------
................................................................................
    imageHeight = height;

    if (mbPtr->drawinfo.state == kThemeStatePressed) {
        /* Offset bitmaps by a bit when the button is pressed. */
        pressed = 1;
    }

  haveText = (butPtr->textWidth != 0 && butPtr->textHeight != 0);
   if (butPtr->compound != COMPOUND_NONE && haveImage && haveText) {
        int x = 0;
        int y = 0;
        textXOffset = 0;
        textYOffset = 0;
        fullWidth = 0;
        fullHeight = 0;

................................................................................
        hiinfo.value = mbPtr->drawinfo.value;
        hiinfo.adornment = mbPtr->drawinfo.adornment;
        hiinfo.animation.time.current = CFAbsoluteTimeGetCurrent();
        if (hiinfo.animation.time.start == 0) {
            hiinfo.animation.time.start = hiinfo.animation.time.current;
        }

        HIThemeDrawButton(&cntrRect, &hiinfo, dc.context, kHIThemeOrientationNormal, &contHIRec);

	TkMacOSXRestoreDrawingContext(&dc);
        MenuButtonContentDrawCB( mbPtr->btnkind, &mbPtr->drawinfo, (MacMenuButton *)mbPtr, 32, true);

    } else {
	if (!TkMacOSXSetupDrawingContext(pixmap, dpPtr->gc, 1, &dc)) {
	    return;
	}
	TkMacOSXRestoreDrawingContext(&dc);
    }
    mbPtr->lastdrawinfo = mbPtr->drawinfo;
................................................................................
 * Side effects:
 *        Sets the btnkind and drawinfo parameters
 *
 *----------------------------------------------------------------------
 */

static void
TkMacOSXComputeMenuButtonParams(TkMenuButton * butPtr, ThemeButtonKind* btnkind, HIThemeButtonDrawInfo *drawinfo)



{
    MacMenuButton *mbPtr = (MacMenuButton *)butPtr;

    if (butPtr->image || butPtr->bitmap) {
	/* TODO: allow for Small and Mini menubuttons. */
	*btnkind = kThemePopupButton;
    } else {
        if (!butPtr->text || !*butPtr->text) {
            *btnkind = kThemeArrowButton;
        } else {
            *btnkind = kThemePopupButton;
        }
    }

    drawinfo->value = kThemeButtonOff;

    if ((mbPtr->flags & FIRST_DRAW) != 0) {
	mbPtr->flags &= ~FIRST_DRAW;
	if (Tk_MacOSXIsAppInFront()) {
................................................................................
 * Side effects:
 *        Sets the button draw parameters.
 *
 *----------------------------------------------------------------------
 */

static void
TkMacOSXComputeMenuButtonDrawParams(TkMenuButton * butPtr, DrawParams * dpPtr)


{
    dpPtr->hasImageOrBitmap = ((butPtr->image != NULL) || (butPtr->bitmap != None));

    dpPtr->border = butPtr->normalBorder;
    if ((butPtr->state == STATE_DISABLED) && (butPtr->disabledFg != NULL)) {
        dpPtr->gc = butPtr->disabledGC;
    } else if (butPtr->state == STATE_ACTIVE) {
        dpPtr->gc = butPtr->activeTextGC;
        dpPtr->border = butPtr->activeBorder;
    } else {







<







 







<
<
<
<
<
<
<
<
<
<





<







 







|
|







 







|
|







 







|
>

|
>







 







|
>
>
>



|


|
<
|
<
<
<







 







|
>
>

|
>







106
107
108
109
110
111
112

113
114
115
116
117
118
119
...
262
263
264
265
266
267
268










269
270
271
272
273

274
275
276
277
278
279
280
...
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
...
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
...
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
...
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751

752



753
754
755
756
757
758
759
...
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
 * explicit width for the button.  Apple also recommends using the same width
 * for all Pop-Up Buttons in a given window.
 */

#define LEFT_INSET 8
#define RIGHT_INSET 28
#define MIN_HEIGHT 22

 
/*
 *----------------------------------------------------------------------
 *
 * TkpCreateMenuButton  --
 *
 *	Allocate a new TkMenuButton structure.
................................................................................
        Tk_SizeOfImage(butPtr->image, &width, &height);
        haveImage = 1;
    } else if (butPtr->bitmap != None) {
        Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height);
        haveImage = 1;
    }











    if (haveImage == 0 || butPtr->compound != COMPOUND_NONE) {
        Tk_FreeTextLayout(butPtr->textLayout);
        butPtr->textLayout = Tk_ComputeTextLayout(butPtr->tkfont,
                butPtr->text, -1, butPtr->wrapLength,
                butPtr->justify, 0, &butPtr->textWidth, &butPtr->textHeight);

        txtWidth = butPtr->textWidth;
        txtHeight = butPtr->textHeight;
        avgWidth = Tk_TextWidth(butPtr->tkfont, "0", 1);
        Tk_GetFontMetrics(butPtr->tkfont, &fm);
    }

    /*
................................................................................
            if (butPtr->height > 0) {
                height = butPtr->height * fm.linespace + 2*butPtr->padY;
            }
        }
    }
    
    butPtr->inset = highlightWidth + butPtr->borderWidth;
    width += LEFT_INSET + RIGHT_INSET + 2*butPtr->inset;
    height += 2*butPtr->inset;
    height = height < MIN_HEIGHT ? MIN_HEIGHT : height;
    Tk_GeometryRequest(butPtr->tkwin, width, height);
    Tk_SetInternalBorder(butPtr->tkwin, butPtr->inset);
}
 
/*
 *----------------------------------------------------------------------
................................................................................
    imageHeight = height;

    if (mbPtr->drawinfo.state == kThemeStatePressed) {
        /* Offset bitmaps by a bit when the button is pressed. */
        pressed = 1;
    }

    haveText = (butPtr->textWidth != 0 && butPtr->textHeight != 0);
    if (butPtr->compound != COMPOUND_NONE && haveImage && haveText) {
        int x = 0;
        int y = 0;
        textXOffset = 0;
        textYOffset = 0;
        fullWidth = 0;
        fullHeight = 0;

................................................................................
        hiinfo.value = mbPtr->drawinfo.value;
        hiinfo.adornment = mbPtr->drawinfo.adornment;
        hiinfo.animation.time.current = CFAbsoluteTimeGetCurrent();
        if (hiinfo.animation.time.start == 0) {
            hiinfo.animation.time.start = hiinfo.animation.time.current;
        }

        HIThemeDrawButton(&cntrRect, &hiinfo, dc.context,
			  kHIThemeOrientationNormal, &contHIRec);
	TkMacOSXRestoreDrawingContext(&dc);
        MenuButtonContentDrawCB( mbPtr->btnkind, &mbPtr->drawinfo,
				 (MacMenuButton *)mbPtr, 32, true);
    } else {
	if (!TkMacOSXSetupDrawingContext(pixmap, dpPtr->gc, 1, &dc)) {
	    return;
	}
	TkMacOSXRestoreDrawingContext(&dc);
    }
    mbPtr->lastdrawinfo = mbPtr->drawinfo;
................................................................................
 * Side effects:
 *        Sets the btnkind and drawinfo parameters
 *
 *----------------------------------------------------------------------
 */

static void
TkMacOSXComputeMenuButtonParams(
    TkMenuButton * butPtr,
    ThemeButtonKind* btnkind,
    HIThemeButtonDrawInfo *drawinfo)
{
    MacMenuButton *mbPtr = (MacMenuButton *)butPtr;

    if (butPtr->image || butPtr->bitmap || butPtr->text) {
	/* TODO: allow for Small and Mini menubuttons. */
	*btnkind = kThemePopupButton;
    } else { /* This should never happen. */

	*btnkind = kThemeArrowButton;



    }

    drawinfo->value = kThemeButtonOff;

    if ((mbPtr->flags & FIRST_DRAW) != 0) {
	mbPtr->flags &= ~FIRST_DRAW;
	if (Tk_MacOSXIsAppInFront()) {
................................................................................
 * Side effects:
 *        Sets the button draw parameters.
 *
 *----------------------------------------------------------------------
 */

static void
TkMacOSXComputeMenuButtonDrawParams(
    TkMenuButton * butPtr,
    DrawParams * dpPtr)
{
    dpPtr->hasImageOrBitmap = ((butPtr->image != NULL) ||
			       (butPtr->bitmap != None));
    dpPtr->border = butPtr->normalBorder;
    if ((butPtr->state == STATE_DISABLED) && (butPtr->disabledFg != NULL)) {
        dpPtr->gc = butPtr->disabledGC;
    } else if (butPtr->state == STATE_ACTIVE) {
        dpPtr->gc = butPtr->activeTextGC;
        dpPtr->border = butPtr->activeBorder;
    } else {