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:
rfm 2009-01-25 13:47:30 +00:00
parent c47c417df7
commit 0d5c221a7d
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> 2009-01-25 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSDocumentController.m (-_nameForHumanReadableType:): Also * Source/NSDocumentController.m (-_nameForHumanReadableType:): Also

View file

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

View file

@ -415,7 +415,7 @@ typedef struct {
[[NSApp mainMenu] setMain: YES]; [[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]; enumerator = [[NSApp windows] objectEnumerator];
while ((window = [enumerator nextObject]) != nil) while ((window = [enumerator nextObject]) != nil)

View file

@ -26,6 +26,7 @@
#include "GSWindowDecorationView.h" #include "GSWindowDecorationView.h"
#include <Foundation/NSEnumerator.h>
#include <Foundation/NSException.h> #include <Foundation/NSException.h>
#include "AppKit/NSColor.h" #include "AppKit/NSColor.h"
@ -417,14 +418,26 @@
[self changeWindowHeight: menubarHeight]; [self changeWindowHeight: menubarHeight];
} }
- (void) removeMenuView: (NSMenuView*)menuView - (NSMenuView*) removeMenuView
{ {
float menubarHeight = [NSMenuView menuBarHeight]; NSEnumerator *e = [[self subviews] objectEnumerator];
NSView *v;
// Unplug the menu view while ((v = [e nextObject]) != nil)
[menuView removeFromSuperviewWithoutNeedingDisplay]; {
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 @end

View file

@ -146,8 +146,8 @@ static BOOL menuBarVisible = YES;
- (NSString*) _locationKey - (NSString*) _locationKey
{ {
NSInterfaceStyle style = NSInterfaceStyleForKey(@"NSMenuInterfaceStyle", nil); NSInterfaceStyle style = NSInterfaceStyleForKey(@"NSMenuInterfaceStyle", nil);
if (style == NSMacintoshInterfaceStyle || if (style == NSMacintoshInterfaceStyle
style == NSWindows95InterfaceStyle) || style == NSWindows95InterfaceStyle)
{ {
return nil; return nil;
} }
@ -1208,14 +1208,35 @@ static BOOL menuBarVisible = YES;
return; 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) 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; return;
} }
contentView = [_aWindow contentView]; _menu.horizontal = [menuRep isHorizontal];
if (_view != nil) if (_view != nil)
{ {
// remove the old representation // remove the old representation
@ -1507,8 +1528,8 @@ static BOOL menuBarVisible = YES;
- (void) _showTornOffMenuIfAny: (NSNotification*)notification - (void) _showTornOffMenuIfAny: (NSNotification*)notification
{ {
NSInterfaceStyle style = NSInterfaceStyleForKey(@"NSMenuInterfaceStyle", nil); NSInterfaceStyle style = NSInterfaceStyleForKey(@"NSMenuInterfaceStyle", nil);
if (style == NSMacintoshInterfaceStyle || if (style == NSMacintoshInterfaceStyle
style == NSWindows95InterfaceStyle) || style == NSWindows95InterfaceStyle)
{ {
return; return;
} }
@ -1748,8 +1769,8 @@ static BOOL menuBarVisible = YES;
NSMenuView *newRep; NSMenuView *newRep;
newRep = [[NSMenuView alloc] initWithFrame: NSZeroRect]; newRep = [[NSMenuView alloc] initWithFrame: NSZeroRect];
if (newStyle == NSMacintoshInterfaceStyle || if (newStyle == NSMacintoshInterfaceStyle
newStyle == NSWindows95InterfaceStyle) || newStyle == NSWindows95InterfaceStyle)
{ {
[newRep setHorizontal: YES]; [newRep setHorizontal: YES];
} }
@ -1761,12 +1782,23 @@ static BOOL menuBarVisible = YES;
[self setMenuRepresentation: newRep]; [self setMenuRepresentation: newRep];
[self _organizeMenu]; [self _organizeMenu];
RELEASE(newRep); 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]]; if (newStyle != NSWindows95InterfaceStyle)
[[self window] setLevel: NSMainMenuWindowLevel]; {
[self _setGeometry]; [[self window] setTitle: [[NSProcessInfo processInfo] processName]];
[self sizeToFit]; [[self window] setLevel: NSMainMenuWindowLevel];
[self _setGeometry];
[self sizeToFit];
}
if ([NSApp isActive]) if ([NSApp isActive])
{ {

View file

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

View file

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

View file

@ -5164,19 +5164,30 @@ current key view.<br />
- (void) setMenu: (NSMenu *)menu - (void) setMenu: (NSMenu *)menu
{ {
NSMenuView *menuView; if ([self menu] != menu)
menuView = [[self menu] menuRepresentation];
if (menuView != nil)
[_wv removeMenuView: menuView];
[super setMenu: menu];
menuView = [menu menuRepresentation];
if (menuView != nil)
{ {
[menu close]; NSMenuView *menuView;
[menuView setHorizontal: YES];
[menuView sizeToFit]; /* Restore the old representation to its original menu after
[_wv addMenuView: menuView]; * 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];
}
} }
} }