mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-22 19:01:15 +00:00
New in-window menu code that should be cleaner than the old one. Will
need a bit of testing and adoptions in the themes. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/branches/in_window_menu@33863 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
43e71bfd18
commit
69f2a0b13e
3 changed files with 51 additions and 48 deletions
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue