2002-04-07 22:02:41 +00:00
|
|
|
/* GormNSMenu.m
|
|
|
|
|
|
|
|
Copyright (C) 2002 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Author: Pierre-Yves Rivaille <pyrivail@ens-lyon.fr>
|
|
|
|
Date: 2002
|
|
|
|
|
|
|
|
This file is part of GNUstep.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
2003-03-03 09:15:48 +00:00
|
|
|
#include "GormNSMenu.h"
|
2002-04-07 22:02:41 +00:00
|
|
|
|
2003-07-24 04:40:55 +00:00
|
|
|
// this must be done here, since Gorm must access this variable..
|
|
|
|
@interface NSResponder (GormNSMenuPrivate)
|
|
|
|
- (NSMenu *) _menu;
|
|
|
|
- (void) _setMenu: (NSMenu *)m;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSResponder (GormNSMenuPrivate)
|
|
|
|
- (NSMenu *) _menu
|
|
|
|
{
|
|
|
|
return _menu;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _setMenu: (NSMenu *)m
|
|
|
|
{
|
|
|
|
_menu = m;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2003-10-13 03:32:51 +00:00
|
|
|
@interface GormNSMenuWindow : NSWindow // NSPanel
|
2002-04-07 22:02:41 +00:00
|
|
|
{
|
2002-09-21 15:24:59 +00:00
|
|
|
GormDocument *_document;
|
2002-04-07 22:02:41 +00:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation GormNSMenuWindow
|
2004-04-26 03:26:23 +00:00
|
|
|
- (BOOL)isExcludedFromWindowsMenu
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2002-04-07 22:02:41 +00:00
|
|
|
- (BOOL)canBecomeMainWindow
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
- (BOOL)canBecomeKeyWindow
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
2002-09-21 15:24:59 +00:00
|
|
|
|
|
|
|
- (void)setMenu: (NSMenu*)menu;
|
|
|
|
{
|
2003-07-24 04:40:55 +00:00
|
|
|
[self _setMenu: menu];
|
2002-09-21 15:24:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setDocument: (GormDocument *)document
|
|
|
|
{
|
|
|
|
_document = document;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)resignMainWindow
|
|
|
|
{
|
|
|
|
[super resignMainWindow];
|
2003-07-24 04:40:55 +00:00
|
|
|
if ([[self _menu] _ownedByPopUp])
|
2002-09-21 15:24:59 +00:00
|
|
|
{
|
|
|
|
[[NSRunLoop currentRunLoop]
|
|
|
|
performSelector: @selector(close)
|
2003-07-24 04:40:55 +00:00
|
|
|
target: [self _menu]
|
2002-09-21 15:24:59 +00:00
|
|
|
argument: nil
|
|
|
|
order: 500000
|
2003-09-28 01:58:57 +00:00
|
|
|
modes: [NSArray arrayWithObjects: NSDefaultRunLoopMode,
|
2002-09-21 15:24:59 +00:00
|
|
|
NSModalPanelRunLoopMode,
|
2003-09-28 01:58:57 +00:00
|
|
|
NSEventTrackingRunLoopMode,
|
|
|
|
nil]];
|
2002-09-21 15:24:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)becomeMainWindow
|
|
|
|
{
|
|
|
|
[super becomeMainWindow];
|
2003-07-24 04:40:55 +00:00
|
|
|
if ([[self _menu] _ownedByPopUp] )
|
2002-09-21 15:24:59 +00:00
|
|
|
{
|
2003-09-28 01:58:57 +00:00
|
|
|
// do nothing...
|
2002-09-21 15:24:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-07 22:02:41 +00:00
|
|
|
- (void) sendEvent: (NSEvent*)theEvent
|
|
|
|
{
|
|
|
|
NSEventType type;
|
|
|
|
|
|
|
|
type = [theEvent type];
|
|
|
|
if (type == NSLeftMouseDown)
|
|
|
|
{
|
|
|
|
[self makeMainWindow];
|
|
|
|
[self makeKeyWindow];
|
|
|
|
}
|
|
|
|
|
|
|
|
[super sendEvent: theEvent];
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2004-05-01 00:05:53 +00:00
|
|
|
/*
|
|
|
|
@interface NSMenu (GormAdditions)
|
|
|
|
- (NSWindow *)_bWindow;
|
|
|
|
- (void) _setBwindow: (NSWindow *)win;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSMenu (GormAdditions)
|
|
|
|
- (NSWindow *)_bWindow
|
|
|
|
{
|
|
|
|
return _bWindow;
|
|
|
|
}
|
|
|
|
- (void) _setBwindow: (NSWindow *)win
|
|
|
|
{
|
|
|
|
_bWindow = win;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
*/
|
|
|
|
|
2002-04-07 22:02:41 +00:00
|
|
|
@implementation GormNSMenu
|
|
|
|
- (BOOL) performKeyEquivalent: (NSEvent*)theEvent
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSPanel*) _createWindow
|
|
|
|
{
|
|
|
|
NSPanel *win = [[GormNSMenuWindow alloc]
|
2002-09-21 15:24:59 +00:00
|
|
|
initWithContentRect: NSZeroRect
|
2003-09-28 01:58:57 +00:00
|
|
|
styleMask: NSBorderlessWindowMask
|
2002-09-21 15:24:59 +00:00
|
|
|
backing: NSBackingStoreBuffered
|
|
|
|
defer: YES];
|
2003-11-15 21:53:00 +00:00
|
|
|
|
2002-09-21 15:24:59 +00:00
|
|
|
[win setMenu: self];
|
2003-09-28 01:58:57 +00:00
|
|
|
[win setLevel: NSSubmenuWindowLevel];
|
2003-10-13 03:32:51 +00:00
|
|
|
// [win setWorksWhenModal: NO];
|
|
|
|
// [win setBecomesKeyOnlyIfNeeded: YES];
|
2003-10-01 23:11:01 +00:00
|
|
|
|
2002-04-07 22:02:41 +00:00
|
|
|
return win;
|
|
|
|
}
|
2003-10-13 03:32:51 +00:00
|
|
|
|
2004-05-01 00:05:53 +00:00
|
|
|
/*
|
2003-10-13 03:32:51 +00:00
|
|
|
- (void) awakeFromDocument: (id)document
|
|
|
|
{
|
2004-05-01 00:05:53 +00:00
|
|
|
NSWindow *win = [self _bWindow];
|
|
|
|
[win close];
|
|
|
|
RELEASE(win);
|
|
|
|
[self _setBwindow: nil];
|
2003-10-13 03:32:51 +00:00
|
|
|
}
|
2004-05-01 00:05:53 +00:00
|
|
|
*/
|
2004-03-04 04:01:09 +00:00
|
|
|
|
|
|
|
- (NSString *)className
|
|
|
|
{
|
|
|
|
return @"NSMenu";
|
|
|
|
}
|
2004-05-01 00:05:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
- (void) display
|
|
|
|
{
|
|
|
|
NSLog(@"Display...");
|
|
|
|
[super display];
|
|
|
|
}
|
|
|
|
*/
|
2002-04-07 22:02:41 +00:00
|
|
|
@end
|
|
|
|
|
2004-01-06 06:11:24 +00:00
|
|
|
/*
|
|
|
|
@interface GormNSMenu (GNUstepExtra)
|
|
|
|
- (void) setTornOff: (BOOL)flag;
|
|
|
|
- (void) _showTornOffMenuIfAny: (NSNotification*)notification;
|
|
|
|
- (void) _showOnActivateApp: (NSNotification*)notification;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation GormNSMenu (GNUstepExtra)
|
|
|
|
- (void) setTornOff: (BOOL)flag
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _showTornOffMenuIfAny: (NSNotification*)notification
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _showOnActivateApp: (NSNotification*)notification
|
|
|
|
{
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
*/
|
|
|
|
|
2002-04-07 22:02:41 +00:00
|
|
|
@implementation NSMenu (GormNSMenu)
|
|
|
|
+ (id) allocSubstitute
|
|
|
|
{
|
|
|
|
return [GormNSMenu alloc];
|
|
|
|
}
|
|
|
|
@end
|