1 |
/* GormNSMenu.m |
2 |
|
3 |
Copyright (C) 2002 Free Software Foundation, Inc. |
4 |
|
5 |
Author: Pierre-Yves Rivaille <pyrivail@ens-lyon.fr> |
6 |
Date: 2002 |
7 |
|
8 |
This file is part of GNUstep. |
9 |
|
10 |
This program is free software; you can redistribute it and/or modify |
11 |
it under the terms of the GNU General Public License as published by |
12 |
the Free Software Foundation; either version 2 of the License, or |
13 |
(at your option) any later version. |
14 |
|
15 |
This program is distributed in the hope that it will be useful, |
16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 |
GNU General Public License for more details. |
19 |
|
20 |
You should have received a copy of the GNU General Public License |
21 |
along with this program; if not, write to the Free Software |
22 |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
23 |
*/ |
24 |
|
25 |
#include "GormNSMenu.h" |
26 |
|
27 |
// this must be done here, since Gorm must access this variable.. |
28 |
@interface NSResponder (GormNSMenuPrivate) |
29 |
- (NSMenu *) _menu; |
30 |
- (void) _setMenu: (NSMenu *)m; |
31 |
@end |
32 |
|
33 |
@implementation NSResponder (GormNSMenuPrivate) |
34 |
- (NSMenu *) _menu |
35 |
{ |
36 |
return _menu; |
37 |
} |
38 |
|
39 |
- (void) _setMenu: (NSMenu *)m |
40 |
{ |
41 |
_menu = m; |
42 |
} |
43 |
@end |
44 |
|
45 |
@interface GormNSMenuWindow : NSWindow |
46 |
{ |
47 |
GormDocument *_document; |
48 |
} |
49 |
@end |
50 |
|
51 |
@implementation GormNSMenuWindow |
52 |
- (BOOL)canBecomeMainWindow |
53 |
{ |
54 |
return YES; |
55 |
} |
56 |
- (BOOL)canBecomeKeyWindow |
57 |
{ |
58 |
return YES; |
59 |
} |
60 |
|
61 |
- (void)setMenu: (NSMenu*)menu; |
62 |
{ |
63 |
[self _setMenu: menu]; |
64 |
} |
65 |
|
66 |
- (void)setDocument: (GormDocument *)document |
67 |
{ |
68 |
_document = document; |
69 |
} |
70 |
|
71 |
- (void)resignMainWindow |
72 |
{ |
73 |
[super resignMainWindow]; |
74 |
if ([[self _menu] _ownedByPopUp]) |
75 |
{ |
76 |
[[NSRunLoop currentRunLoop] |
77 |
performSelector: @selector(close) |
78 |
target: [self _menu] |
79 |
argument: nil |
80 |
order: 500000 |
81 |
modes: [NSArray arrayWithObjects: NSDefaultRunLoopMode, |
82 |
NSModalPanelRunLoopMode, |
83 |
NSEventTrackingRunLoopMode, |
84 |
nil]]; |
85 |
} |
86 |
} |
87 |
|
88 |
- (void)becomeMainWindow |
89 |
{ |
90 |
[super becomeMainWindow]; |
91 |
if ([[self _menu] _ownedByPopUp] ) |
92 |
{ |
93 |
// do nothing... |
94 |
} |
95 |
} |
96 |
|
97 |
- (void) sendEvent: (NSEvent*)theEvent |
98 |
{ |
99 |
NSEventType type; |
100 |
|
101 |
type = [theEvent type]; |
102 |
if (type == NSLeftMouseDown) |
103 |
{ |
104 |
[self makeMainWindow]; |
105 |
[self makeKeyWindow]; |
106 |
} |
107 |
|
108 |
[super sendEvent: theEvent]; |
109 |
} |
110 |
@end |
111 |
|
112 |
@implementation GormNSMenu |
113 |
- (BOOL) performKeyEquivalent: (NSEvent*)theEvent |
114 |
{ |
115 |
return NO; |
116 |
} |
117 |
|
118 |
- (NSPanel*) _createWindow |
119 |
{ |
120 |
NSPanel *win = [[GormNSMenuWindow alloc] |
121 |
initWithContentRect: NSZeroRect |
122 |
styleMask: NSBorderlessWindowMask |
123 |
backing: NSBackingStoreBuffered |
124 |
defer: YES]; |
125 |
|
126 |
[win setMenu: self]; |
127 |
[win setLevel: NSSubmenuWindowLevel]; |
128 |
|
129 |
return win; |
130 |
} |
131 |
@end |
132 |
|
133 |
@implementation NSMenu (GormNSMenu) |
134 |
+ (id) allocSubstitute |
135 |
{ |
136 |
return [GormNSMenu alloc]; |
137 |
} |
138 |
@end |