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"
|
2004-08-02 03:18:45 +00:00
|
|
|
#include <AppKit/NSPopUpButton.h>
|
|
|
|
#include <AppKit/NSPopUpButtonCell.h>
|
2004-08-05 05:34:41 +00:00
|
|
|
#include <InterfaceBuilder/InterfaceBuilder.h>
|
2003-07-24 04:40:55 +00:00
|
|
|
|
2004-08-02 03:18:45 +00:00
|
|
|
@interface GormNSMenuWindow : NSPanel
|
2002-04-07 22:02:41 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation GormNSMenuWindow
|
|
|
|
- (BOOL)canBecomeMainWindow
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
- (BOOL)canBecomeKeyWindow
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
2002-09-21 15:24:59 +00:00
|
|
|
|
|
|
|
- (void)resignMainWindow
|
|
|
|
{
|
|
|
|
[super resignMainWindow];
|
2004-07-27 06:20:45 +00:00
|
|
|
if ([[self menu] _ownedByPopUp])
|
2002-09-21 15:24:59 +00:00
|
|
|
{
|
|
|
|
[[NSRunLoop currentRunLoop]
|
|
|
|
performSelector: @selector(close)
|
2004-07-27 06:20:45 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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];
|
|
|
|
}
|
2004-07-21 01:49:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
2004-07-27 06:20:45 +00:00
|
|
|
[self setMenu: nil];
|
|
|
|
[super dealloc];
|
2004-07-21 01:49:07 +00:00
|
|
|
}
|
2002-04-07 22:02:41 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation GormNSMenu
|
2004-08-05 05:34:41 +00:00
|
|
|
- (id) initWithCoder: (NSCoder *)coder
|
|
|
|
{
|
|
|
|
if((self = [super initWithCoder: coder]) != nil)
|
|
|
|
{
|
|
|
|
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
|
|
|
[nc addObserver: self
|
|
|
|
selector: @selector(handleNotification:)
|
|
|
|
name: IBSelectionChangedNotification
|
|
|
|
object: nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) handleNotification: (NSNotification *)notification
|
|
|
|
{
|
|
|
|
id<IBEditors> object = [notification object];
|
|
|
|
if(object != nil)
|
|
|
|
{
|
|
|
|
id edited = [object editedObject];
|
|
|
|
if(self != edited && [self _ownedByPopUp])
|
|
|
|
{
|
|
|
|
[self close];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-07 22:02:41 +00:00
|
|
|
- (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];
|
2004-05-01 13:02:04 +00:00
|
|
|
[win setExcludedFromWindowsMenu: YES];
|
2004-07-27 06:20:45 +00:00
|
|
|
RETAIN(win); // FIXME: Argh.. this may leak.. temporary fix.
|
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-03-04 04:01:09 +00:00
|
|
|
- (NSString *)className
|
|
|
|
{
|
|
|
|
return @"NSMenu";
|
|
|
|
}
|
2004-05-02 11:39:58 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2004-07-21 01:49:07 +00:00
|
|
|
// These methods are purely for debugging purposes...
|
|
|
|
/*
|
2004-05-02 11:39:58 +00:00
|
|
|
- (void) display
|
|
|
|
{
|
2004-05-13 22:48:14 +00:00
|
|
|
NSDebugLog(@"In GormNSMenu display...");
|
2004-05-02 11:39:58 +00:00
|
|
|
[super display];
|
|
|
|
}
|
2004-07-21 01:49:07 +00:00
|
|
|
|
|
|
|
- (id) retain
|
|
|
|
{
|
|
|
|
NSLog(@"Being retained... %d: %@", [self retainCount], self);
|
|
|
|
return [super retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (oneway void) release
|
|
|
|
{
|
|
|
|
NSLog(@"Being released... %d: %@", [self retainCount], self);
|
|
|
|
[super release];
|
|
|
|
}
|
2004-08-05 05:34:41 +00:00
|
|
|
*/
|
|
|
|
#endif
|
2004-07-21 01:49:07 +00:00
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
2004-08-05 05:34:41 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver: self
|
|
|
|
name: IBSelectionChangedNotification
|
|
|
|
object: nil];
|
2004-07-21 01:49:07 +00:00
|
|
|
[super dealloc];
|
|
|
|
}
|
2004-08-05 05:34:41 +00:00
|
|
|
|
2002-04-07 22:02:41 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSMenu (GormNSMenu)
|
|
|
|
+ (id) allocSubstitute
|
|
|
|
{
|
|
|
|
return [GormNSMenu alloc];
|
|
|
|
}
|
|
|
|
@end
|