diff options
-rw-r--r-- | doc/menu.n | 18 | ||||
-rw-r--r-- | library/demos/menu.tcl | 21 | ||||
-rw-r--r-- | macosx/tkMacOSXColor.c | 14 | ||||
-rw-r--r-- | macosx/tkMacOSXColor.h | 2 | ||||
-rw-r--r-- | macosx/tkMacOSXDefault.h | 23 | ||||
-rw-r--r-- | macosx/tkMacOSXInit.c | 30 | ||||
-rw-r--r-- | macosx/tkMacOSXMenu.c | 70 |
7 files changed, 110 insertions, 68 deletions
@@ -40,7 +40,7 @@ entry at the top. If so, it will exist as entry 0 of the menu and the other entries will number starting at 1. The default menu bindings arrange for the menu to be torn off when the tear-off entry is invoked. -This option is ignored under Aqua/Mac OS X, where menus cannot +This option is ignored under Aqua/MacOS, where menus cannot be torn off. .OP \-tearoffcommand tearOffCommand TearOffCommand If this option has a non-empty value, then it specifies a Tcl command @@ -54,7 +54,7 @@ and menu \fB.x.y\fR is torn off to create a new menu \fB.x.tearoff1\fR, then the command .QW "\fBa b .x.y .x.tearoff1\fR" will be invoked. -This option is ignored under Aqua/Mac OS X, where menus cannot +This option is ignored under Aqua/MacOS, where menus cannot be torn off. .OP \-title title Title The string will be used to title the window created when this menu is @@ -523,8 +523,8 @@ supported by all entry types. \fB\-activebackground \fIvalue\fR . Specifies a background color to use for displaying this entry when it -is active. -If this option is specified as an empty string (the default), then the +is active. This option is ignored on Aqua/MacOS. +If it is specified as an empty string (the default), then the \fB\-activebackground\fR option for the overall menu is used. If the \fBtk_strictMotif\fR variable has been set to request strict Motif compliance, then this option is ignored and the \fB\-background\fR @@ -534,7 +534,7 @@ This option is not available for separator or tear-off entries. \fB\-activeforeground \fIvalue\fR . Specifies a foreground color to use for displaying this entry when it -is active. +is active. This option is ignored on Aqua/macOS. If this option is specified as an empty string (the default), then the \fB\-activeforeground\fR option for the overall menu is used. This option is not available for separator or tear-off entries. @@ -552,7 +552,8 @@ for separator or tear-off entries. . Specifies a background color to use for displaying this entry when it is in the normal state (neither active nor disabled). -If this option is specified as an empty string (the default), then the +This option is ignored on Aqua/macOS. +If it is specified as an empty string (the default), then the \fB\-background\fR option for the overall menu is used. This option is not available for separator or tear-off entries. .TP @@ -573,7 +574,7 @@ This option is not available for separator or tear-off entries. When this option is zero, the entry appears below the previous entry. When this option is one, the entry appears at the top of a new column in the menu. -This option is ignored on Aqua/Mac OS X, where menus are always a single +This option is ignored on Aqua/macOS, where menus are always a single column. .TP \fB\-command \fIvalue\fR @@ -603,7 +604,8 @@ This option is not available for separator or tear-off entries. . Specifies a foreground color to use for displaying this entry when it is in the normal state (neither active nor disabled). -If this option is specified as an empty string (the default), then the +This option is ignored on Aqua/macOS. +If it is specified as an empty string (the default), then the \fB\-foreground\fR option for the overall menu is used. This option is not available for separator or tear-off entries. .TP diff --git a/library/demos/menu.tcl b/library/demos/menu.tcl index a76bd54..fbb0069 100644 --- a/library/demos/menu.tcl +++ b/library/demos/menu.tcl @@ -151,9 +151,24 @@ $m entryconfigure "Does almost nothing also" -image lilearth -compound left \ set m $w.menu.colors $w.menu add cascade -label "Colors" -menu $m -underline 1 menu $m -tearoff 1 -foreach i {red orange yellow green blue} { - $m add command -label $i -background $i -command [list \ - puts "You invoked \"$i\"" ] +if {[tk windowingsystem] eq "aqua"} { + # Aqua ignores the -background and -foreground options, but a compound + # button can be used for selecting colors. + foreach i {red orange yellow green blue} { + image create photo image_$i -height 16 -width 16 + image_$i put black -to 0 0 16 1 + image_$i put black -to 0 1 1 16 + image_$i put black -to 0 15 16 16 + image_$i put black -to 15 1 16 16 + image_$i put $i -to 1 1 15 15 + $m add command -label $i -image image_$i -compound left -command [list \ + puts "You invoked \"$i\"" ] + } +} else { + foreach i {red orange yellow green blue} { + $m add command -label $i -background $i -command [list \ + puts "You invoked \"$i\"" ] + } } $w configure -menu $w.menu diff --git a/macosx/tkMacOSXColor.c b/macosx/tkMacOSXColor.c index 0ab4f97..b8aca2a 100644 --- a/macosx/tkMacOSXColor.c +++ b/macosx/tkMacOSXColor.c @@ -177,7 +177,7 @@ TkMacOSXRGBPixel( unsigned long green, unsigned long blue) { - MacPixel p; + MacPixel p = {0}; p.pixel.colortype = rgbColor; p.pixel.value = ((red & 0xff) << 16) | ((green & 0xff) << 8) | @@ -207,7 +207,7 @@ MODULE_SCOPE unsigned long TkMacOSXClearPixel( void) { - MacPixel p; + MacPixel p = {0}; p.pixel.value = 0; p.pixel.colortype = clearColor; return p.ulong; @@ -236,7 +236,7 @@ SystemColorDatum* GetEntryFromPixel( unsigned long pixel) { - MacPixel p; + MacPixel p = {0}; int index = rgbColorIndex; p.ulong = pixel; @@ -314,6 +314,10 @@ GetRGBA( } } break; + case clearColor: + rgba[0] = rgba[1] = rgba[2] = 1.0; + rgba[3] = 0; + break; case semantic: if (entry->index == controlAccentIndex && useFakeAccentColor) { #if MAC_OS_X_VERSION_MIN_REQUIRED < 101400 @@ -332,8 +336,6 @@ GetRGBA( } [color getComponents: rgba]; break; - case clearColor: - rgba[3] = 0; default: break; } @@ -596,7 +598,7 @@ TkpGetColor( if (strncasecmp(name, "system", 6) == 0) { Tcl_HashEntry *hPtr = Tcl_FindHashEntry(&systemColors, name + 6); - MacPixel p; + MacPixel p = {0}; if (hPtr != NULL) { SystemColorDatum *entry = (SystemColorDatum *)Tcl_GetHashValue(hPtr); diff --git a/macosx/tkMacOSXColor.h b/macosx/tkMacOSXColor.h index a030589..1b4bab6 100644 --- a/macosx/tkMacOSXColor.h +++ b/macosx/tkMacOSXColor.h @@ -87,7 +87,7 @@ typedef struct { static SystemColorDatum systemColorData[] = { {"Pixel", rgbColor, 0, NULL, 0, NULL }, -{"Transparent", clearColor, 0, NULL, 0, NULL }, +{"Transparent", clearColor, 0, NULL, 0, NULL }, {"Highlight", HIBrush, kThemeBrushPrimaryHighlightColor, NULL, 0, NULL }, {"HighlightSecondary", HIBrush, kThemeBrushSecondaryHighlightColor, NULL, 0, NULL }, diff --git a/macosx/tkMacOSXDefault.h b/macosx/tkMacOSXDefault.h index 0dc9db9..1df20f7 100644 --- a/macosx/tkMacOSXDefault.h +++ b/macosx/tkMacOSXDefault.h @@ -46,6 +46,7 @@ #define TROUGH "#c3c3c3" #define INDICATOR "#b03060" #define DISABLED "systemDisabledControlTextColor" +#define IGNORED "#abcdef" /* * Defaults for labels, buttons, checkbuttons, and radiobuttons: @@ -301,24 +302,24 @@ * Defaults for menus overall: */ -#define DEF_MENU_ACTIVE_BG_COLOR NORMAL_BG /*ignored*/ -#define DEF_MENU_ACTIVE_BG_MONO NORMAL_BG /*ignored*/ +#define DEF_MENU_ACTIVE_BG_COLOR IGNORED +#define DEF_MENU_ACTIVE_BG_MONO IGNORED #define DEF_MENU_ACTIVE_BORDER_WIDTH "0" -#define DEF_MENU_ACTIVE_FG_COLOR NORMAL_FG -#define DEF_MENU_ACTIVE_FG_MONO NORMAL_FG +#define DEF_MENU_ACTIVE_FG_COLOR IGNORED +#define DEF_MENU_ACTIVE_FG_MONO IGNORED #define DEF_MENU_ACTIVE_RELIEF "flat" -#define DEF_MENU_BG_COLOR NORMAL_BG /*ignored*/ -#define DEF_MENU_BG_MONO NORMAL_BG /*ignored*/ +#define DEF_MENU_BG_COLOR "#000001" /* Detects custom bg. */ +#define DEF_MENU_BG_MONO IGNORED #define DEF_MENU_BORDER_WIDTH "0" #define DEF_MENU_CURSOR "arrow" -#define DEF_MENU_DISABLED_FG_COLOR DISABLED -#define DEF_MENU_DISABLED_FG_MONO DISABLED +#define DEF_MENU_DISABLED_FG_COLOR IGNORED +#define DEF_MENU_DISABLED_FG_MONO "" #define DEF_MENU_FONT "menu" /* special: see tkMacOSXMenu.c */ -#define DEF_MENU_FG NORMAL_FG +#define DEF_MENU_FG "#010000" /* Detects custom fg. */ #define DEF_MENU_POST_COMMAND "" #define DEF_MENU_RELIEF "flat" -#define DEF_MENU_SELECT_COLOR "systemSelectedMenuItemTextColor" -#define DEF_MENU_SELECT_MONO "systemSelectedMenuItemTextColor" +#define DEF_MENU_SELECT_COLOR IGNORED +#define DEF_MENU_SELECT_MONO IGNORED #define DEF_MENU_TAKE_FOCUS "0" #define DEF_MENU_TEAROFF "0" #define DEF_MENU_TEAROFF_CMD NULL diff --git a/macosx/tkMacOSXInit.c b/macosx/tkMacOSXInit.c index 06ff367..996fc05 100644 --- a/macosx/tkMacOSXInit.c +++ b/macosx/tkMacOSXInit.c @@ -103,29 +103,37 @@ static int TkMacOSXGetAppPathCmd(ClientData cd, Tcl_Interp *ip, #endif [self _setupWindowNotifications]; [self _setupApplicationNotifications]; +} + +-(void)applicationDidFinishLaunching:(NSNotification *)notification +{ + (void)notification; + + /* + * Initialize event processing. + */ + + TkMacOSXInitAppleEvents(_eventInterp); /* - * Construct the menu bar. + * Initialize the graphics context. */ - _defaultMainMenu = nil; - [self _setupMenus]; + TkMacOSXUseAntialiasedText(_eventInterp, -1); + TkMacOSXInitCGDrawing(_eventInterp, TRUE, 0); /* - * Initialize event processing. + * Construct the menu bar. */ - TkMacOSXInitAppleEvents(_eventInterp); + _defaultMainMenu = nil; + [self _setupMenus]; /* - * Initialize the graphics context. + * Initialize graphics. */ + TkMacOSXUseAntialiasedText(_eventInterp, -1); TkMacOSXInitCGDrawing(_eventInterp, TRUE, 0); -} - --(void)applicationDidFinishLaunching:(NSNotification *)notification -{ - (void)notification; /* * It is not safe to force activation of the NSApp until this method is diff --git a/macosx/tkMacOSXMenu.c b/macosx/tkMacOSXMenu.c index de2bb4e..f97d8e3 100644 --- a/macosx/tkMacOSXMenu.c +++ b/macosx/tkMacOSXMenu.c @@ -316,12 +316,6 @@ TKBackgroundLoop *backgroundLoop = nil; if (menuPtr && mePtr) { Tcl_Interp *interp = menuPtr->interp; - /* - * Add time for errors to fire if necessary. This is sub-optimal - * but avoids issues with Tcl/Cocoa event loop integration. - */ - - //Tcl_Sleep(100); Tcl_Preserve(interp); Tcl_Preserve(menuPtr); @@ -685,7 +679,6 @@ TkpConfigureMenuEntry( NSString *keyEquivalent = @""; NSUInteger modifierMask = NSCommandKeyMask; NSMenu *submenu = nil; - NSDictionary *attributes; int imageWidth, imageHeight; GC gc = (mePtr->textGC ? mePtr->textGC : mePtr->menuPtr->textGC); Tcl_Obj *fontPtr = (mePtr->fontPtr ? @@ -714,9 +707,7 @@ TkpConfigureMenuEntry( &imageHeight); image = TkMacOSXGetNSImageFromBitmap(mePtr->menuPtr->display, bitmap, gc, imageWidth, imageHeight); - if (gc->foreground == defaultFg) { - [image setTemplate:YES]; - } + [image setTemplate:YES]; } [menuItem setImage:image]; if ((!image || mePtr->compound != COMPOUND_NONE) && mePtr->labelPtr && @@ -730,23 +721,48 @@ TkpConfigureMenuEntry( } } [menuItem setTitle:title]; - if (strcmp(Tcl_GetString(fontPtr), "menu") || gc->foreground != defaultFg - || gc->background != defaultBg) { - attributes = TkMacOSXNSFontAttributesForFont(Tk_GetFontFromObj( - mePtr->menuPtr->tkwin, fontPtr)); - if (gc->foreground != defaultFg || gc->background != defaultBg) { - NSColor *color = TkMacOSXGetNSColor(gc, - gc->foreground!=defaultFg? gc->foreground:gc->background); - - attributes = [[attributes mutableCopy] autorelease]; - [(NSMutableDictionary *) attributes setObject:color - forKey:NSForegroundColorAttributeName]; - } - if (attributes) { - attributedTitle = [[[NSAttributedString alloc] - initWithString:title attributes:attributes] autorelease]; - } + +#if 0 + + /* + * The -background and -foreground options are now ignored in Aqua. + * See ticket [635167af14]. + */ + + NSDictionary fontAttributes = TkMacOSXNSFontAttributesForFont( + Tk_GetFontFromObj(mePtr->menuPtr->tkwin, fontPtr)); + NSMutableDictionary *attributes = [fontAttributes mutableCopy]; + static unsigned long defaultBg = 0, defaultFg = 0; + if (defaultBg == 0) { + tkColor *tkColPtr = TkpGetColor(NULL, DEF_MENU_BG_COLOR); + defaultBg = tkColPtr->color.pixel; + ckfree(tkColPtr); + } + if (defaultFg == 0) { + tkColor *tkColPtr = TkpGetColor(NULL, DEF_MENU_FG); + defaultFg = tkColPtr->color.pixel; + ckfree(tkColPtr); + } + if (gc->foreground != defaultFg) { + NSColor *fgcolor = TkMacOSXGetNSColor(gc, gc->foreground); + [attributes setObject:fgcolor + forKey:NSForegroundColorAttributeName]; } + if (gc->background != defaultBg) { + NSColor *bgcolor = TkMacOSXGetNSColor(gc, gc->background); + [attributes setObject:bgcolor + forKey:NSBackgroundColorAttributeName]; + } + +#else + + NSDictionary *attributes = TkMacOSXNSFontAttributesForFont( + Tk_GetFontFromObj(mePtr->menuPtr->tkwin, fontPtr)); + +#endif + + attributedTitle = [[NSAttributedString alloc] initWithString:title + attributes:attributes]; [menuItem setAttributedTitle:attributedTitle]; [menuItem setEnabled:(mePtr->state != ENTRY_DISABLED)]; [menuItem setState:((mePtr->type == CHECK_BUTTON_ENTRY || @@ -1664,8 +1680,6 @@ TkMacOSXClearMenubarActive(void) void TkpMenuInit(void) { - // TkColor *tkColPtr; - NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; #define observe(n, s) \ |