per-window menu setting tweaks.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@27686 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2009-01-25 13:47:30 +00:00
parent 246576a001
commit ab54f4450e
8 changed files with 100 additions and 35 deletions

View file

@ -1,3 +1,12 @@
2009-01-25 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSWindowDecorationView.m:
* Source/NSMenu.m:
* Source/NSWindow.m:
* Source/NSToolbarFrameworkPrivate.h:
Tweaks to allow setting of a menu in a window (and unsetting it)
repeatedly as you switch between themes.
2009-01-25 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSDocumentController.m (-_nameForHumanReadableType:): Also

View file

@ -128,8 +128,8 @@ static BOOL _isInInterfaceBuilder = NO;
NSMenuView *newRep;
newRep = [[NSMenuView alloc] initWithFrame: NSZeroRect];
if (newStyle == NSMacintoshInterfaceStyle ||
newStyle == NSWindows95InterfaceStyle)
if (newStyle == NSMacintoshInterfaceStyle
|| newStyle == NSWindows95InterfaceStyle)
{
[newRep setHorizontal: YES];
}

View file

@ -415,7 +415,7 @@ typedef struct {
[[NSApp mainMenu] setMain: YES];
/*
* Mark all windows as needing redisplaying to thos the new theme.
* Mark all windows as needing redisplaying to show the new theme.
*/
enumerator = [[NSApp windows] objectEnumerator];
while ((window = [enumerator nextObject]) != nil)

View file

@ -26,6 +26,7 @@
#include "GSWindowDecorationView.h"
#include <Foundation/NSEnumerator.h>
#include <Foundation/NSException.h>
#include "AppKit/NSColor.h"
@ -417,14 +418,26 @@
[self changeWindowHeight: menubarHeight];
}
- (void) removeMenuView: (NSMenuView*)menuView
- (NSMenuView*) removeMenuView
{
float menubarHeight = [NSMenuView menuBarHeight];
NSEnumerator *e = [[self subviews] objectEnumerator];
NSView *v;
// Unplug the menu view
[menuView removeFromSuperviewWithoutNeedingDisplay];
while ((v = [e nextObject]) != nil)
{
if ([v isKindOfClass: [NSMenuView class]] == YES)
{
float menubarHeight = [NSMenuView menuBarHeight];
/* Unplug the menu view and return it so that it can be
* restored to its original menu if necessary.
*/
[RETAIN(v) removeFromSuperviewWithoutNeedingDisplay];
[self changeWindowHeight: -menubarHeight];
[self changeWindowHeight: -menubarHeight];
return AUTORELEASE(v);
}
}
}
@end

View file

@ -146,8 +146,8 @@ static BOOL menuBarVisible = YES;
- (NSString*) _locationKey
{
NSInterfaceStyle style = NSInterfaceStyleForKey(@"NSMenuInterfaceStyle", nil);
if (style == NSMacintoshInterfaceStyle ||
style == NSWindows95InterfaceStyle)
if (style == NSMacintoshInterfaceStyle
|| style == NSWindows95InterfaceStyle)
{
return nil;
}
@ -1208,14 +1208,35 @@ static BOOL menuBarVisible = YES;
return;
}
_menu.horizontal = [menuRep isHorizontal];
/* If we are replacing a menu representation with a new version,
* we should display it in the same view as the old representation.
* If we can't find a view for that, we display in the content view
* of our default window.
*/
if ([_view superview] == nil)
{
contentView = [_aWindow contentView];
}
else
{
contentView = [_view superview];
}
if (_view == menuRep)
{
/* Hack ... if the representation was 'borrowed' for an in-window
* menu, we will still have it recorded as ours, but it won't be
* in our view hierarchy, so we have to re-add it.
*/
if (contentView != [menuRep superview])
{
[contentView addSubview: menuRep];
}
return;
}
contentView = [_aWindow contentView];
_menu.horizontal = [menuRep isHorizontal];
if (_view != nil)
{
// remove the old representation
@ -1507,8 +1528,8 @@ static BOOL menuBarVisible = YES;
- (void) _showTornOffMenuIfAny: (NSNotification*)notification
{
NSInterfaceStyle style = NSInterfaceStyleForKey(@"NSMenuInterfaceStyle", nil);
if (style == NSMacintoshInterfaceStyle ||
style == NSWindows95InterfaceStyle)
if (style == NSMacintoshInterfaceStyle
|| style == NSWindows95InterfaceStyle)
{
return;
}
@ -1748,8 +1769,8 @@ static BOOL menuBarVisible = YES;
NSMenuView *newRep;
newRep = [[NSMenuView alloc] initWithFrame: NSZeroRect];
if (newStyle == NSMacintoshInterfaceStyle ||
newStyle == NSWindows95InterfaceStyle)
if (newStyle == NSMacintoshInterfaceStyle
|| newStyle == NSWindows95InterfaceStyle)
{
[newRep setHorizontal: YES];
}
@ -1761,12 +1782,23 @@ static BOOL menuBarVisible = YES;
[self setMenuRepresentation: newRep];
[self _organizeMenu];
RELEASE(newRep);
if (newStyle == NSWindows95InterfaceStyle)
{
[[NSApp mainWindow] setMenu: self];
}
else if ([[NSApp mainWindow] menu] == self)
{
[[NSApp mainWindow] setMenu: nil];
}
}
[[self window] setTitle: [[NSProcessInfo processInfo] processName]];
[[self window] setLevel: NSMainMenuWindowLevel];
[self _setGeometry];
[self sizeToFit];
if (newStyle != NSWindows95InterfaceStyle)
{
[[self window] setTitle: [[NSProcessInfo processInfo] processName]];
[[self window] setLevel: NSMainMenuWindowLevel];
[self _setGeometry];
[self sizeToFit];
}
if ([NSApp isActive])
{

View file

@ -116,7 +116,7 @@
@end
@interface GSWindowDecorationView (Menu)
- (void) addMenuView: (NSMenuView*)menuView;
- (void) removeMenuView: (NSMenuView*)menuView;
- (NSMenuView*) removeMenuView;
@end
#endif // _NSToolbarFrameworkPrivate_h_INCLUDE

View file

@ -970,8 +970,8 @@ GSSetDragTypes(NSView* obj, NSArray *types)
[newView _viewWillMoveToWindow: _window];
[newView _viewWillMoveToSuperview: self];
[newView setNextResponder: self];
[_sub_views insertObject: newView
atIndex: index];
[_sub_views insertObject: newView
atIndex: index];
_rFlags.has_subviews = 1;
[newView resetCursorRects];
[newView setNeedsDisplay: YES];

View file

@ -5164,19 +5164,30 @@ current key view.<br />
- (void) setMenu: (NSMenu *)menu
{
NSMenuView *menuView;
menuView = [[self menu] menuRepresentation];
if (menuView != nil)
[_wv removeMenuView: menuView];
[super setMenu: menu];
menuView = [menu menuRepresentation];
if (menuView != nil)
if ([self menu] != menu)
{
[menu close];
[menuView setHorizontal: YES];
[menuView sizeToFit];
[_wv addMenuView: menuView];
NSMenuView *menuView;
/* Restore the old representation to its original menu after
* removing it from the window. If we didn't do this, the menu
* representation would be left without a partent view or
* window to draw in.
*/
menuView = [_wv removeMenuView];
[[self menu] setMenuRepresentation: menuView];
/* Set the new menu, and transfer the new menu representation
* to the window decoration view.
*/
[super setMenu: menu];
menuView = [menu menuRepresentation];
if (menuView != nil)
{
[menu close];
[menuView setHorizontal: YES];
[menuView sizeToFit];
[_wv addMenuView: menuView];
}
}
}