diff options
author | culler <culler> | 2020-08-15 17:30:46 (GMT) |
---|---|---|
committer | culler <culler> | 2020-08-15 17:30:46 (GMT) |
commit | d50d5fd2ad4143c7717ff55b88ceaf9cd6a62357 (patch) | |
tree | 733706851ed1d02c1ee17841d6a761de182bf9b3 /macosx/tkMacOSXMenu.c | |
parent | be1bfa39359eca9014e16377610340cce09fcfe6 (diff) | |
parent | 596eb400c9a112d7fa41054520f238ab50438eff (diff) | |
download | tk-d50d5fd2ad4143c7717ff55b88ceaf9cd6a62357.zip tk-d50d5fd2ad4143c7717ff55b88ceaf9cd6a62357.tar.gz tk-d50d5fd2ad4143c7717ff55b88ceaf9cd6a62357.tar.bz2 |
Merge trunk
Diffstat (limited to 'macosx/tkMacOSXMenu.c')
-rw-r--r-- | macosx/tkMacOSXMenu.c | 61 |
1 files changed, 32 insertions, 29 deletions
diff --git a/macosx/tkMacOSXMenu.c b/macosx/tkMacOSXMenu.c index 230cead..05dc5e1 100644 --- a/macosx/tkMacOSXMenu.c +++ b/macosx/tkMacOSXMenu.c @@ -95,7 +95,6 @@ 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; -static unsigned long defaultBg = 0, defaultFg = 0; static SInt32 menuMarkColumnWidth = 0, menuIconTrailingEdgeMargin = 0; static SInt32 menuTextLeadingEdgeMargin = 0, menuTextTrailingEdgeMargin = 0; static SInt16 menuItemExtraHeight = 0, menuItemExtraWidth = 0; @@ -124,7 +123,7 @@ static int ModifierCharWidth(Tk_Font tkfont); * the menu was posted. For example, opening a menu during the Rube Goldberg * demo would cause the animation to stop. This was also the case for * menubuttons. - * + * * The TKBackground object below works around this problem, and allows a Tk * event loop to run while a menu is open. It is a subclass of NSThread which * inserts requests to call [NSApp _runBackgroundLoop] onto the queue @@ -139,34 +138,35 @@ static int ModifierCharWidth(Tk_Font tkfont); @implementation TKBackgroundLoop - (void) main { + NSAutoreleasePool *pool = [NSAutoreleasePool new]; NSArray *modeArray = [NSArray arrayWithObjects: NSEventTrackingRunLoopMode, nil]; while(1) { - + /* * Queue a request to process Tk events during event tracking. */ - - [NSApp performSelectorOnMainThread:@selector(_runBackgroundLoop) + + [NSApp performSelectorOnMainThread:@selector(_runBackgroundLoop) withObject:nil - waitUntilDone:true + waitUntilDone:true modes:modeArray]; - if (self.cancelled) { + if ([self isCancelled]) { [NSThread exit]; } - + /* * Allow the tracked events to be processed too. */ [NSThread sleepForTimeInterval:0.001]; - } + } + [pool drain]; } @end TKBackgroundLoop *backgroundLoop = nil; - #pragma mark TKMenu /* @@ -692,8 +692,19 @@ TkpConfigureMenuEntry( NSDictionary *attributes; int imageWidth, imageHeight; GC gc = (mePtr->textGC ? mePtr->textGC : mePtr->menuPtr->textGC); - Tcl_Obj *fontPtr = (mePtr->fontPtr ? mePtr->fontPtr : - mePtr->menuPtr->fontPtr); + Tcl_Obj *fontPtr = (mePtr->fontPtr ? + mePtr->fontPtr : mePtr->menuPtr->fontPtr); + static unsigned long defaultBg, defaultFg; + static int initialized = 0; + + if (!initialized) { + TkColor *tkColPtr = TkpGetColor(NULL, DEF_MENU_BG_COLOR); + defaultBg = tkColPtr->color.pixel; + ckfree(tkColPtr); + tkColPtr = TkpGetColor(NULL, DEF_MENU_FG); + defaultFg = tkColPtr->color.pixel; + ckfree(tkColPtr); + } if (mePtr->image) { Tk_SizeOfImage(mePtr->image, &imageWidth, &imageHeight); @@ -708,7 +719,6 @@ TkpConfigureMenuEntry( image = TkMacOSXGetNSImageWithBitmap(mePtr->menuPtr->display, bitmap, gc, imageWidth, imageHeight); if (gc->foreground == defaultFg) { - // Use a semantic foreground color by default [image setTemplate:YES]; } } @@ -1109,8 +1119,8 @@ TkpSetMainMenubar( if (winPtr->wmInfoPtr && winPtr->wmInfoPtr->menuPtr && - winPtr->wmInfoPtr->menuPtr->masterMenuPtr) { - menubar = winPtr->wmInfoPtr->menuPtr->masterMenuPtr->tkwin; + winPtr->wmInfoPtr->menuPtr->mainMenuPtr) { + menubar = winPtr->wmInfoPtr->menuPtr->mainMenuPtr->tkwin; } /* @@ -1164,25 +1174,25 @@ static void CheckForSpecialMenu( TkMenu *menuPtr) /* The menu we are checking */ { - if (!menuPtr->masterMenuPtr->tkwin) { + if (!menuPtr->mainMenuPtr->tkwin) { return; } for (TkMenuEntry *cascadeEntryPtr = menuPtr->menuRefPtr->parentEntryPtr; cascadeEntryPtr; cascadeEntryPtr = cascadeEntryPtr->nextCascadePtr) { if (cascadeEntryPtr->menuPtr->menuType == MENUBAR - && cascadeEntryPtr->menuPtr->masterMenuPtr->tkwin) { - TkMenu *masterMenuPtr = cascadeEntryPtr->menuPtr->masterMenuPtr; + && cascadeEntryPtr->menuPtr->mainMenuPtr->tkwin) { + TkMenu *mainMenuPtr = cascadeEntryPtr->menuPtr->mainMenuPtr; int i = 0; Tcl_DString ds; Tcl_DStringInit(&ds); - Tcl_DStringAppend(&ds, Tk_PathName(masterMenuPtr->tkwin), -1); + Tcl_DStringAppend(&ds, Tk_PathName(mainMenuPtr->tkwin), -1); while (specialMenus[i].name) { Tcl_DStringAppend(&ds, specialMenus[i].name, specialMenus[i].len); if (strcmp(Tcl_DStringValue(&ds), - Tk_PathName(menuPtr->masterMenuPtr->tkwin)) == 0) { + Tk_PathName(menuPtr->mainMenuPtr->tkwin)) == 0) { cascadeEntryPtr->entryFlags |= specialMenus[i].flag; } else { cascadeEntryPtr->entryFlags &= ~specialMenus[i].flag; @@ -1341,7 +1351,7 @@ TkpComputeStandardMenuGeometry( * Do nothing if this menu is a clone. */ - if (menuPtr->tkwin == NULL || menuPtr->masterMenuPtr != menuPtr) { + if (menuPtr->tkwin == NULL || menuPtr->mainMenuPtr != menuPtr) { return; } @@ -1692,7 +1702,7 @@ Tk_MacOSXTurnOffMenus(void) void TkpMenuInit(void) { - TkColor *tkColPtr; + // TkColor *tkColPtr; NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; @@ -1703,13 +1713,6 @@ TkpMenuInit(void) #undef observe [NSMenuItem setUsesUserKeyEquivalents:NO]; - tkColPtr = TkpGetColor(NULL, DEF_MENU_BG_COLOR); - defaultBg = tkColPtr->color.pixel; - ckfree(tkColPtr); - tkColPtr = TkpGetColor(NULL, DEF_MENU_FG); - defaultFg = tkColPtr->color.pixel; - ckfree(tkColPtr); - ChkErr(GetThemeMetric, kThemeMetricMenuMarkColumnWidth, &menuMarkColumnWidth); ChkErr(GetThemeMetric, kThemeMetricMenuTextLeadingEdgeMargin, |