diff --git a/ChangeLog b/ChangeLog index fea3c8169..47214b894 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,12 @@ +2011-10-01 Fred Kiefer + + * Source/GSThemeMenu.m, + * Source/GSThemeMenu.m, + * Source/GSWindowDecorationView.m: Rewrite of the in-window menu handling. + 2011-09-12 German Arias - * Source/GSThemeMenu.m (-setMenu:forWindow:): Improvements to + * Source/GSThemeMenu.m (-setMenu:forWindow:): Improvements to menu in window. 2011-09-12 Fred Kiefer diff --git a/Source/GSThemeMenu.m b/Source/GSThemeMenu.m index 589254d6e..b0da05ead 100644 --- a/Source/GSThemeMenu.m +++ b/Source/GSThemeMenu.m @@ -61,52 +61,29 @@ forWindow: (NSWindow *)window { GSWindowDecorationView *wv = [window windowView]; - if ([window menu] == nil && menu != nil) - { - // NSData *data = [NSArchiver archivedDataWithRootObject: menu]; // - NSMenu *newMenu = [menu copy]; - NSMenuView *menuView = nil; - /* - * Set the new menu - */ - [window _setMenu: newMenu]; + // protect against stupid calls from updateAllWindowsWithMenu: + if ([window menu] == menu) + return; - /* - * And transfer the new menu representation to the window decoration view. - */ - menuView = [newMenu menuRepresentation]; - if (menuView != nil) - { - [menu close]; - [menuView setHorizontal: YES]; - [wv addMenuView: menuView]; - [menuView sizeToFit]; - } - } - else - { - /* We copy "Windows" menu, since this can't be updated - * with calling -update:. However, with this way if the - * menus have a different name this will not work (for - * example "Window" instead "Windows"). So the programmer - * must be careful here. - */ - - NSMenuItem *windowsItem, *oldWindowsItem; - NSMenu *newWindowsMenu; - - windowsItem = [menu itemWithTitle: _(@"Windows")]; - if (windowsItem != nil && [windowsItem hasSubmenu]) - { - //Get the new "Windows" menu - newWindowsMenu = [[windowsItem submenu] copy]; - - //Set this menu into the menu in this window - oldWindowsItem = [[window menu] itemWithTitle: _(@"Windows")]; - [oldWindowsItem setSubmenu: newWindowsMenu]; - } - } + // Prevent recursion + [window _setMenu: menu]; + + // Remove any possible old menu view + [wv removeMenuView]; + + //NSLog(@"Adding menu %@ to window %@", menu, window); + if (menu != nil) + { + NSMenuView *menuView = [[NSMenuView alloc] initWithFrame: NSZeroRect]; + + [menuView setMenu: menu]; + [menuView setHorizontal: YES]; + [menuView setInterfaceStyle: NSWindows95InterfaceStyle]; + [wv addMenuView: menuView]; + [menuView sizeToFit]; + RELEASE(menuView); + } } - (void) rightMouseDisplay: (NSMenu *)menu diff --git a/Source/GSWindowDecorationView.m b/Source/GSWindowDecorationView.m index d6a247387..503d26190 100644 --- a/Source/GSWindowDecorationView.m +++ b/Source/GSWindowDecorationView.m @@ -294,7 +294,7 @@ static inline NSRect RectWithSizeScaledByFactor(NSRect aRect, CGFloat factor) if (hasMenu) { - NSMenuView *menuView; + NSMenuView *menuView = nil; GSTheme *theme = [GSTheme theme]; float menuBarHeight = [theme menuHeightForWindow: _window]; NSRect menuRect = @@ -302,8 +302,17 @@ static inline NSRect RectWithSizeScaledByFactor(NSRect aRect, CGFloat factor) (NSMaxY(contentRect) + 1) - menuBarHeight, contentViewFrame.size.width, menuBarHeight); - - menuView = [[_window menu] menuRepresentation]; + NSEnumerator *e = [[self subviews] objectEnumerator]; + NSView *v; + + while ((v = [e nextObject]) != nil) + { + if ([v isKindOfClass: [NSMenuView class]] == YES) + { + menuView = (NSMenuView *)v; + break; + } + } [menuView setFrame: menuRect]; contentViewFrame.size.height -= menuBarHeight; } diff --git a/Source/NSMenuView.m b/Source/NSMenuView.m index dfb60def2..7344b1b64 100644 --- a/Source/NSMenuView.m +++ b/Source/NSMenuView.m @@ -86,6 +86,17 @@ static NSMapTable *viewInfo = 0; /* A menu's title is an instance of this class */ @class NSButton; +@interface NSMenu (Private) +- (void) _attachMenu: (NSMenu*)aMenu; +@end + +@implementation NSMenu (Private) +- (void) _attachMenu: (NSMenu*)aMenu +{ + _attachedMenu = aMenu; +} +@end + @interface NSMenuView (Private) - (BOOL) _rootIsHorizontal: (BOOL*)isAppMenu; @end @@ -548,6 +559,8 @@ static NSMapTable *viewInfo = 0; else { [attachedMenu close]; + // Unselect the active item + [self setHighlightedItemIndex: -1]; } } @@ -577,7 +590,11 @@ static NSMapTable *viewInfo = 0; else { NSDebugLLog (@"NSMenu", @"Will open normal: %@", attachableMenu); - [attachableMenu display]; + // FIXME: Only resize when needed + [attachableMenu sizeToFit]; + [[attachableMenu window] setFrameOrigin: [self locationForSubmenu: attachableMenu]]; + [_attachedMenu _attachMenu: attachableMenu]; + [[attachableMenu window] orderFrontRegardless]; } }