First attempt at in window menus.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@27649 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2009-01-22 09:19:22 +00:00
parent 1803fa7fc5
commit dda7640fa5
5 changed files with 165 additions and 90 deletions

View file

@ -1,3 +1,12 @@
2009-01-22 Fred Kiefer <FredKiefer@gmx.de>
* Source/GSWindowDecorationView.m: Add handling of in-window
menu. Simplify code for toolbar handling.
* Source/NSToolbarFrameworkPrivate.h: Publish ne methods.
* Source/NSWindow.m (-setMenu:): Set the menu as in-window menu.
* Source/NSMenuView.m: Set the frame width to the screen width in
setHorizontal: and not in sizeToFit.
2009-01-21 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSOutlineView.m: Don't ask if the topmost item is expandable.

View file

@ -29,6 +29,7 @@
#include <Foundation/NSException.h>
#include "AppKit/NSColor.h"
#include "AppKit/NSMenuView.h"
#include "AppKit/NSWindow.h"
#include "GNUstepGUI/GSDisplayServer.h"
#include "GNUstepGUI/GSTheme.h"
@ -122,7 +123,11 @@
styleMask: aStyle];
NSToolbar *tb = [_window toolbar];
// TODO: Handle toolbar and others
if ([_window menu] != nil)
{
content.size.height -= [NSMenuView menuBarHeight];
}
if ([tb isVisible])
{
GSToolbarView *tv = [tb _toolbarView];
@ -138,7 +143,11 @@
{
NSToolbar *tb = [_window toolbar];
// TODO: Handle toolbar and others
if ([_window menu] != nil)
{
aRect.size.height += [NSMenuView menuBarHeight];
}
if ([tb isVisible])
{
GSToolbarView *tv = [tb _toolbarView];
@ -193,31 +202,34 @@
[GSServerForWindow(window) docedited: documentEdited : windowNumber];
}
/*
* Special setFrame: implementation - a minimal autoresize mechanism
*/
- (void) setFrame: (NSRect)frameRect
- (void) layout
{
NSSize oldSize = _frame.size;
NSView *cv = [_window contentView];
// Should resize all subviews
NSRect contentViewFrame;
NSToolbar *tb = [_window toolbar];
NSRect frame = [window frame];
// Wouldn't it be better to rely on the autoresize mechanism?
_autoresizes_subviews = NO;
[super setFrame: frameRect];
frame.origin = NSZeroPoint;
contentViewFrame = [isa contentRectForFrameRect: frame
styleMask: [window styleMask]];
contentRect = [isa contentRectForFrameRect: frameRect
styleMask: [window styleMask]];
if ([_window menu] != nil)
{
NSMenuView *menuView;
float menuBarHeight = [NSMenuView menuBarHeight];
// Safety Check.
[cv setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
[cv resizeWithOldSuperviewSize: oldSize];
menuView = [[_window menu] menuRepresentation];
[menuView setFrame: NSMakeRect(
contentViewFrame.origin.x,
NSMaxY(contentViewFrame) - menuBarHeight,
contentViewFrame.size.width,
menuBarHeight)];
contentViewFrame.size.height -= menuBarHeight;
}
// FIXME: Should resize all subviews
if ([tb isVisible])
{
GSToolbarView *tv = [tb _toolbarView];
NSRect contentViewFrame = [cv frame];
float newToolbarViewHeight;
// If the width changed we may need to recalculate the height
@ -230,12 +242,60 @@
newToolbarViewHeight = [tv _heightFromLayout];
[tv setFrame: NSMakeRect(
contentViewFrame.origin.x,
NSMaxY(contentViewFrame),
NSMaxY(contentViewFrame) - newToolbarViewHeight,
contentViewFrame.size.width,
newToolbarViewHeight)];
contentViewFrame.size.height -= newToolbarViewHeight;
}
}
- (void) changeWindowHeight: (float)difference
{
NSRect orgWindowFrame;
NSRect windowFrame;
NSRect windowContentFrame;
contentRect.size.height += difference;
windowFrame = [isa frameRectForContentRect: contentRect
styleMask: [window styleMask]];
// Set the local frame without changing the contents view
windowContentFrame = windowFrame;
windowContentFrame.origin = NSZeroPoint;
_autoresizes_subviews = NO;
[super setFrame: windowContentFrame];
// Keep the top of the window at the same place
orgWindowFrame = [window frame];
windowFrame.origin.y = orgWindowFrame.origin.y + orgWindowFrame.size.height - windowFrame.size.height;
windowFrame.origin.x = orgWindowFrame.origin.x;
// then resize the window
[window setFrame: windowFrame display: YES];
}
/*
* Special setFrame: implementation - a minimal autoresize mechanism
*/
- (void) setFrame: (NSRect)frameRect
{
NSSize oldSize = _frame.size;
NSView *cv = [_window contentView];
// Wouldn't it be better to rely on the autoresize mechanism?
_autoresizes_subviews = NO;
[super setFrame: frameRect];
contentRect = [isa contentRectForFrameRect: frameRect
styleMask: [window styleMask]];
// Safety Check.
[cv setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
[cv resizeWithOldSuperviewSize: oldSize];
[self layout];
}
- (void) setInputState: (int)state
{
inputState = state;
@ -291,74 +351,32 @@
- (void) addToolbarView: (GSToolbarView*)toolbarView
{
NSView *contentView = [window contentView];
NSRect contentViewFrame = [contentView frame];
float newToolbarViewHeight;
NSRect orgWindowFrame;
NSRect windowFrame;
NSRect windowContentFrame;
[toolbarView setFrameSize: NSMakeSize(contentViewFrame.size.width, 100)];
[toolbarView setFrameSize: NSMakeSize(contentRect.size.width, 100)];
// Will recalculate the layout
[toolbarView _reload];
newToolbarViewHeight = [toolbarView _heightFromLayout];
// Plug the toolbar view
[toolbarView setFrame: NSMakeRect(
contentViewFrame.origin.x,
NSMaxY(contentViewFrame),
contentViewFrame.size.width,
contentRect.origin.x,
NSMaxY(contentRect),
contentRect.size.width,
newToolbarViewHeight)];
[self addSubview: toolbarView];
orgWindowFrame = [window frame];
windowContentFrame = [isa contentRectForFrameRect: orgWindowFrame
styleMask: [window styleMask]];
windowContentFrame.size.height += newToolbarViewHeight;
windowFrame = [isa frameRectForContentRect: windowContentFrame
styleMask: [window styleMask]];
// Keep the top of the window at the same place
windowFrame.origin.y += orgWindowFrame.size.height - windowFrame.size.height;
// Set the local frames
contentRect = windowContentFrame;
windowContentFrame = windowFrame;
windowContentFrame.origin = NSZeroPoint;
_autoresizes_subviews = NO;
[super setFrame: windowContentFrame];
// then resize the window
[window setFrame: windowFrame display: YES];
[self changeWindowHeight: newToolbarViewHeight];
}
- (void) removeToolbarView: (GSToolbarView *)toolbarView
{
float toolbarViewHeight = [toolbarView frame].size.height;
NSRect orgWindowFrame;
NSRect windowFrame;
NSRect windowContentFrame;
// Unplug the toolbar view
[toolbarView removeFromSuperviewWithoutNeedingDisplay];
orgWindowFrame = [window frame];
windowContentFrame = [isa contentRectForFrameRect: orgWindowFrame
styleMask: [window styleMask]];
windowContentFrame.size.height -= toolbarViewHeight;
windowFrame = [isa frameRectForContentRect: windowContentFrame
styleMask: [window styleMask]];
// Keep the top of the window at the same place
windowFrame.origin.y += orgWindowFrame.size.height - windowFrame.size.height;
// Set the local frames
contentRect = windowContentFrame;
windowContentFrame = windowFrame;
windowContentFrame.origin = NSZeroPoint;
_autoresizes_subviews = NO;
[super setFrame: windowContentFrame];
// then resize the window and display
[window setFrame: windowFrame display: YES];
[self changeWindowHeight: -toolbarViewHeight];
}
- (void) adjustToolbarView: (GSToolbarView *)toolbarView
@ -370,36 +388,48 @@
if (toolbarViewHeight != newToolbarViewHeight)
{
NSRect orgWindowFrame;
NSRect windowFrame;
NSRect windowContentFrame;
[toolbarView setFrame: NSMakeRect(
toolbarViewFrame.origin.x,
toolbarViewFrame.origin.y + (toolbarViewHeight - newToolbarViewHeight),
toolbarViewFrame.size.width,
newToolbarViewHeight)];
orgWindowFrame = [window frame];
windowContentFrame = [isa contentRectForFrameRect: orgWindowFrame
styleMask: [window styleMask]];
windowContentFrame.size.height -= toolbarViewHeight - newToolbarViewHeight;
windowFrame = [isa frameRectForContentRect: windowContentFrame
styleMask: [window styleMask]];
windowFrame.origin.y += orgWindowFrame.size.height - windowFrame.size.height;
// Set the local frames
contentRect = windowContentFrame;
windowContentFrame = windowFrame;
windowContentFrame.origin = NSZeroPoint;
_frame = windowContentFrame;
// then resize the window and display
[window setFrame: windowFrame display: YES];
[self changeWindowHeight: newToolbarViewHeight - toolbarViewHeight];
}
}
@end
@implementation GSWindowDecorationView (Menu)
- (void) addMenuView: (NSMenuView*)menuView
{
float menubarHeight = [NSMenuView menuBarHeight];
// Plug the menu view
[menuView setFrame: NSMakeRect(
contentRect.origin.x,
NSMaxY(contentRect),
contentRect.size.width,
menubarHeight)];
[self addSubview: menuView];
[self changeWindowHeight: menubarHeight];
}
- (void) removeMenuView: (NSMenuView*)menuView
{
float menubarHeight = [NSMenuView menuBarHeight];
// Unplug the menu view
[menuView removeFromSuperviewWithoutNeedingDisplay];
[self changeWindowHeight: -menubarHeight];
}
@end
@implementation GSBackendWindowDecorationView
+ (void) offsets: (float *)l : (float *)r : (float *)t : (float *)b

View file

@ -296,10 +296,14 @@ _addLeftBorderOffsetToRect(NSRect aRect)
{
if (flag == YES && _horizontal == NO)
{
NSRect scRect = [[NSScreen mainScreen] frame];
GSIArray a = NSZoneMalloc(NSDefaultMallocZone(), sizeof(GSIArray_t));
GSIArrayInitWithZoneAndCapacity(a, NSDefaultMallocZone(), 8);
NSMapInsert(viewInfo, self, a);
scRect.size.height = [NSMenuView menuBarHeight];
[self setFrameSize: scRect.size];
}
else if (flag == NO && _horizontal == YES)
{
@ -644,13 +648,16 @@ _addLeftBorderOffsetToRect(NSRect aRect)
unsigned i;
unsigned howMany = [_itemCells count];
float currentX = 8;
NSRect scRect = [[NSScreen mainScreen] frame];
// NSRect scRect = [[NSScreen mainScreen] frame];
GSIArrayRemoveAllItems(cellRects);
/*
scRect.size.height = [NSMenuView menuBarHeight];
[self setFrameSize: scRect.size];
_cellSize.height = scRect.size.height;
*/
_cellSize.height = [NSMenuView menuBarHeight];
for (i = 0; i < howMany; i++)
{
@ -947,6 +954,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
{
NSRect aRect = [self rectOfItemAtIndex: i];
//NSLog(@"indexOfItemAtPoint called for %@ %@ %d %@", self, NSStringFromPoint(point), i, NSStringFromRect(aRect));
aRect = _addLeftBorderOffsetToRect(aRect);
if (NSMouseInRect(point, aRect, NO))
@ -1347,6 +1355,7 @@ _addLeftBorderOffsetToRect(NSRect aRect)
int index;
location = [_window mouseLocationOutsideOfEventStream];
index = [self indexOfItemAtPoint: location];
if (event == original)

View file

@ -30,6 +30,7 @@
#ifndef _NSToolbarFrameworkPrivate_h_INCLUDE
#define _NSToolbarFrameworkPrivate_h_INCLUDE
#include "AppKit/NSMenuView.h"
#include "AppKit/NSToolbar.h"
#include "AppKit/NSToolbarItem.h"
#include "GNUstepGUI/GSToolbarView.h"
@ -113,5 +114,9 @@
- (void) removeToolbarView: (GSToolbarView *)toolbarView;
- (void) adjustToolbarView: (GSToolbarView *)toolbarView;
@end
@interface GSWindowDecorationView (Menu)
- (void) addMenuView: (NSMenuView*)menuView;
- (void) removeMenuView: (NSMenuView*)menuView;
@end
#endif // _NSToolbarFrameworkPrivate_h_INCLUDE

View file

@ -5106,6 +5106,8 @@ current key view.<br />
if (!toolbar)
return;
[toolbar setVisible: !isVisible];
if (isVisible)
{
[_wv removeToolbarView: [toolbar _toolbarView]];
@ -5115,8 +5117,6 @@ current key view.<br />
[_wv addToolbarView: [toolbar _toolbarView]];
}
[toolbar setVisible: !isVisible];
[self display];
}
@ -5158,6 +5158,28 @@ current key view.<br />
@end
@implementation NSWindow (Menu)
- (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)
{
[menu close];
[menuView setHorizontal: YES];
[menuView sizeToFit];
[_wv addMenuView: menuView];
}
}
@end
/*
* GNUstep backend methods
*/