summaryrefslogtreecommitdiffstats
path: root/macosx
diff options
context:
space:
mode:
authorculler <culler>2020-11-17 20:51:51 (GMT)
committerculler <culler>2020-11-17 20:51:51 (GMT)
commit9d94caca32ae897acbb3fb2e32f97f8cb81f2de8 (patch)
tree61fcc51ebe26338191fedbfbc21df2dccb03a05e /macosx
parent0050bf7b52205d79ae1721df9921a8a65ad38c4f (diff)
downloadtk-9d94caca32ae897acbb3fb2e32f97f8cb81f2de8.zip
tk-9d94caca32ae897acbb3fb2e32f97f8cb81f2de8.tar.gz
tk-9d94caca32ae897acbb3fb2e32f97f8cb81f2de8.tar.bz2
Try initializing menus a bit later and dealing with menu item background color.
Diffstat (limited to 'macosx')
-rw-r--r--macosx/tkMacOSXColor.h2
-rw-r--r--macosx/tkMacOSXDefault.h21
-rw-r--r--macosx/tkMacOSXInit.c30
-rw-r--r--macosx/tkMacOSXMenu.c65
4 files changed, 69 insertions, 49 deletions
diff --git a/macosx/tkMacOSXColor.h b/macosx/tkMacOSXColor.h
index 5a57c88..0f4518d 100644
--- a/macosx/tkMacOSXColor.h
+++ b/macosx/tkMacOSXColor.h
@@ -89,7 +89,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 29b672a..af0a06b 100644
--- a/macosx/tkMacOSXDefault.h
+++ b/macosx/tkMacOSXDefault.h
@@ -46,6 +46,7 @@
#define TROUGH "#c3c3c3"
#define INDICATOR "#b03060"
#define DISABLED "#a3a3a3"
+#define IGNORED "#abcdef"
/*
* Defaults for labels, buttons, checkbuttons, and radiobuttons:
@@ -297,23 +298,23 @@
* Defaults for menus overall:
*/
-#define DEF_MENU_ACTIVE_BG_COLOR "systemMenuActive"
-#define DEF_MENU_ACTIVE_BG_MONO BLACK
+#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 "systemMenuActiveText"
-#define DEF_MENU_ACTIVE_FG_MONO WHITE
-#define DEF_MENU_BG_COLOR "systemMenu"
-#define DEF_MENU_BG_MONO WHITE
+#define DEF_MENU_ACTIVE_FG_COLOR IGNORED
+#define DEF_MENU_ACTIVE_FG_MONO 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 "systemMenuDisabled"
+#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 "systemMenuText"
+#define DEF_MENU_FG "#010000" /* Detects custom fg. */
#define DEF_MENU_POST_COMMAND ""
#define DEF_MENU_RELIEF "flat"
-#define DEF_MENU_SELECT_COLOR "systemMenuActive"
-#define DEF_MENU_SELECT_MONO BLACK
+#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 3d5a996..ee05eb5 100644
--- a/macosx/tkMacOSXMenu.c
+++ b/macosx/tkMacOSXMenu.c
@@ -95,6 +95,12 @@ static int gNoTkMenus = 0; /* This is used by Tk_MacOSXTurnOffMenus as
* the flag that Tk is not to draw any
* menus. */
static int inPostMenu = 0;
+
+/*
+ * These colors are never used. We compare current settings with these to
+ * detect whether they have been changed from the default.
+ */
+
static unsigned long defaultBg = 0, defaultFg = 0;
static SInt32 menuMarkColumnWidth = 0, menuIconTrailingEdgeMargin = 0;
static SInt32 menuTextLeadingEdgeMargin = 0, menuTextTrailingEdgeMargin = 0;
@@ -320,12 +326,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);
@@ -693,7 +693,8 @@ TkpConfigureMenuEntry(
NSString *keyEquivalent = @"";
NSUInteger modifierMask = NSCommandKeyMask;
NSMenu *submenu = nil;
- NSDictionary *attributes;
+ NSDictionary *fontAttributes;
+ NSMutableDictionary *attributes;
int imageWidth, imageHeight;
GC gc = (mePtr->textGC ? mePtr->textGC : mePtr->menuPtr->textGC);
Tcl_Obj *fontPtr = (mePtr->fontPtr ? mePtr->fontPtr :
@@ -711,9 +712,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 &&
@@ -727,23 +726,36 @@ 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];
- }
+ fontAttributes = TkMacOSXNSFontAttributesForFont(Tk_GetFontFromObj(
+ mePtr->menuPtr->tkwin, fontPtr));
+ attributes = [fontAttributes mutableCopy];
+ if (gc->foreground != defaultFg) {
+
+ /*
+ * Apple's default foreground color changes to white when the menuitem is
+ * selected. If a custom foreground color is used then the color will be
+ * the same for selected and unselected menu items.
+ */
+
+ NSColor *fgcolor = TkMacOSXGetNSColor(gc, gc->foreground);
+ [attributes setObject:fgcolor
+ forKey:NSForegroundColorAttributeName];
}
+ if (gc->background != defaultBg) {
+
+ /*
+ * Setting a background color looks awful. But setting the background should
+ * not be the same as setting the foreground. As a compromise, if the background
+ * color is set we draw an underline in that color.
+ */
+ NSColor *bgcolor = TkMacOSXGetNSColor(gc, gc->background);
+ [attributes setObject:bgcolor
+ forKey:NSUnderlineColorAttributeName];
+ [attributes setObject:[NSNumber numberWithInt:NSUnderlineStyleDouble]
+ forKey:NSUnderlineStyleAttributeName];
+ }
+ attributedTitle = [[[NSAttributedString alloc]
+ initWithString:title attributes:attributes] autorelease];
[menuItem setAttributedTitle:attributedTitle];
[menuItem setEnabled:!(mePtr->state == ENTRY_DISABLED)];
[menuItem setState:((mePtr->type == CHECK_BUTTON_ENTRY ||
@@ -1696,7 +1708,6 @@ void
TkpMenuInit(void)
{
TkColor *tkColPtr;
-
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
#define observe(n, s) \