1/** <title>NSPanel</title> 2 3 <abstract>Panel window class and related functions</abstract> 4 5 Copyright (C) 1996 Free Software Foundation, Inc. 6 7 Author: Scott Christley <scottc@net-community.com> 8 Date: 1996 9 10 This file is part of the GNUstep GUI Library. 11 12 This library is free software; you can redistribute it and/or 13 modify it under the terms of the GNU Lesser General Public 14 License as published by the Free Software Foundation; either 15 version 2 of the License, or (at your option) any later version. 16 17 This library is distributed in the hope that it will be useful, 18 but WITHOUT ANY WARRANTY; without even the implied warranty of 19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 Lesser General Public License for more details. 21 22 You should have received a copy of the GNU Lesser General Public 23 License along with this library; see the file COPYING.LIB. 24 If not, see <http://www.gnu.org/licenses/> or write to the 25 Free Software Foundation, 51 Franklin Street, Fifth Floor, 26 Boston, MA 02110-1301, USA. 27*/ 28 29#import "config.h" 30 31#import <Foundation/NSCoder.h> 32#import "AppKit/NSButton.h" 33#import "AppKit/NSEvent.h" 34#import "AppKit/NSImage.h" 35#import "AppKit/NSPanel.h" 36#import "AppKit/NSTextField.h" 37 38@implementation NSPanel 39 40/* 41 * Class methods 42 */ 43+ (void)initialize 44{ 45 if (self == [NSPanel class]) 46 { 47 [self setVersion: 1]; 48 } 49} 50 51/* 52 * Instance methods 53 */ 54- (id) init 55{ 56 int style = NSTitledWindowMask | NSClosableWindowMask; 57 58 return [self initWithContentRect: NSZeroRect 59 styleMask: style 60 backing: NSBackingStoreBuffered 61 defer: NO]; 62} 63 64- (id) initWithContentRect: (NSRect)contentRect 65 styleMask: (NSUInteger)aStyle 66 backing: (NSBackingStoreType)bufferingType 67 defer: (BOOL)flag 68{ 69 self = [super initWithContentRect: contentRect 70 styleMask: aStyle 71 backing: bufferingType 72 defer: flag]; 73 if (nil == self) 74 { 75 return nil; 76 } 77 78 if ((_styleMask & NSUtilityWindowMask) == NSUtilityWindowMask) 79 { 80 [self setFloatingPanel: YES]; 81 } 82 83 return self; 84} 85 86- (void) _initDefaults 87{ 88 [super _initDefaults]; 89 [self setReleasedWhenClosed: NO]; 90 [self setHidesOnDeactivate: YES]; 91 [self setExcludedFromWindowsMenu: YES]; 92} 93 94- (BOOL) canBecomeKeyWindow 95{ 96 return YES; 97} 98 99- (BOOL) canBecomeMainWindow 100{ 101 return NO; 102} 103 104/* 105 * If we receive an escape, close. 106 */ 107- (void) keyDown: (NSEvent*)theEvent 108{ 109 if ([@"\e" isEqual: [theEvent charactersIgnoringModifiers]] 110 && ([self styleMask] & NSClosableWindowMask) == NSClosableWindowMask) 111 [self close]; 112 else 113 [super keyDown: theEvent]; 114} 115 116/**<p>Returns whether the NSPanel is a floating panel, e.g. the window level 117 is NSFloatingWindowLevel instead of NSNormalWindowLevel.</p> 118 <p>See Also: -setFloatingPanel: </p> 119 */ 120- (BOOL) isFloatingPanel 121{ 122 return _isFloatingPanel; 123} 124 125/**<p>Sets whether the NSPanel is a floating panel, e.g. the window level 126 is NSFloatingWindowLevel instead of NSNormalWindowLevel.</p> 127 <p>See Also: -isFloatingPanel [NSWindow-setLevel:]</p> 128 */ 129- (void) setFloatingPanel: (BOOL)flag 130{ 131 if (_isFloatingPanel != flag) 132 { 133 _isFloatingPanel = flag; 134 if (flag == YES) 135 { 136 [self setLevel: NSFloatingWindowLevel]; 137 } 138 else 139 { 140 [self setLevel: NSNormalWindowLevel]; 141 } 142 } 143} 144 145/**<p>Returns whether the NSPanel can receive events when another window/panel 146 runs modally.</p><p>See Also: -setWorksWhenModal: 147 [NSApplication-runModalSession:]</p> 148 */ 149- (BOOL) worksWhenModal 150{ 151 return _worksWhenModal; 152} 153 154/**<p>Sets whether the NSPanel can receive events when another window/panel 155 runs modally.</p>See Also: -worksWhenModal [NSApplication-runModalSession:] 156 */ 157- (void) setWorksWhenModal: (BOOL)flag 158{ 159 _worksWhenModal = flag; 160} 161 162/**<p>Returns whether if the NSPanel becomes key window only when a view 163 require to be the first responder.</p> 164 <p>See Also: -setBecomesKeyOnlyIfNeeded: [NSView-needsPanelToBecomeKey] 165 [NSWindow-sendEvent:]</p> 166 */ 167- (BOOL) becomesKeyOnlyIfNeeded 168{ 169 return _becomesKeyOnlyIfNeeded; 170} 171 172/**<p>Sets whether if the NSPanel becomes key window only when a view 173 require to be the first responder.</p> 174 <p>See Also: -setBecomesKeyOnlyIfNeeded: [NSView-needsPanelToBecomeKey] 175 [NSWindow-sendEvent:]</p> 176 */ 177- (void) setBecomesKeyOnlyIfNeeded: (BOOL)flag 178{ 179 _becomesKeyOnlyIfNeeded = flag; 180} 181 182/* 183 * NSCoding protocol 184 */ 185- (void) encodeWithCoder: (NSCoder*)aCoder 186{ 187 BOOL flag; 188 189 [super encodeWithCoder: aCoder]; 190 if ([aCoder allowsKeyedCoding]) 191 { 192 // Nothing to do here, for keyed coding this is handled by NSWindowTemplate. 193 // Calling the above method should throw an NSInvalidArgumentException. 194 } 195 else 196 { 197 flag = _becomesKeyOnlyIfNeeded; 198 [aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag]; 199 flag = _isFloatingPanel; 200 [aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag]; 201 flag = _worksWhenModal; 202 [aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag]; 203 } 204} 205 206- (id) initWithCoder: (NSCoder*)aDecoder 207{ 208 BOOL flag; 209 210 self = [super initWithCoder: aDecoder]; 211 if (nil == self) 212 return nil; 213 214 if ([aDecoder allowsKeyedCoding]) 215 { 216 // Nothing to do here, for keyed coding this is handled by NSWindowTemplate. 217 // Calling the above method should throw an NSInvalidArgumentException. 218 } 219 else 220 { 221 [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &flag]; 222 [self setBecomesKeyOnlyIfNeeded: flag]; 223 [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &flag]; 224 [self setFloatingPanel: flag]; 225 [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &flag]; 226 [self setWorksWhenModal: flag]; 227 } 228 229 return self; 230} 231 232@end /* NSPanel */ 233 234