libs-gui/Source/NSPanel.m

234 lines
5.7 KiB
Mathematica
Raw Permalink Normal View History

/** <title>NSPanel</title>
<abstract>Panel window class and related functions</abstract>
Copyright (C) 1996 Free Software Foundation, Inc.
Author: Scott Christley <scottc@net-community.com>
Date: 1996
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; see the file COPYING.LIB.
If not, see <http://www.gnu.org/licenses/> or write to the
Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#import "config.h"
#import <Foundation/NSCoder.h>
#import "AppKit/NSButton.h"
#import "AppKit/NSEvent.h"
#import "AppKit/NSImage.h"
#import "AppKit/NSPanel.h"
#import "AppKit/NSTextField.h"
@implementation NSPanel
/*
* Class methods
*/
+ (void)initialize
{
if (self == [NSPanel class])
{
[self setVersion: 1];
}
}
/*
* Instance methods
*/
- (id) init
{
int style = NSTitledWindowMask | NSClosableWindowMask;
return [self initWithContentRect: NSZeroRect
styleMask: style
backing: NSBackingStoreBuffered
defer: NO];
}
- (id) initWithContentRect: (NSRect)contentRect
styleMask: (NSUInteger)aStyle
backing: (NSBackingStoreType)bufferingType
defer: (BOOL)flag
{
self = [super initWithContentRect: contentRect
styleMask: aStyle
backing: bufferingType
defer: flag];
if (nil == self)
{
return nil;
}
if ((_styleMask & NSUtilityWindowMask) == NSUtilityWindowMask)
{
[self setFloatingPanel: YES];
}
return self;
}
- (void) _initDefaults
{
[super _initDefaults];
[self setReleasedWhenClosed: NO];
[self setHidesOnDeactivate: YES];
[self setExcludedFromWindowsMenu: YES];
}
- (BOOL) canBecomeKeyWindow
{
return YES;
}
- (BOOL) canBecomeMainWindow
{
return NO;
}
/*
* If we receive an escape, close.
*/
- (void) keyDown: (NSEvent*)theEvent
{
if ([@"\e" isEqual: [theEvent charactersIgnoringModifiers]]
&& ([self styleMask] & NSClosableWindowMask) == NSClosableWindowMask)
[self close];
else
[super keyDown: theEvent];
}
/**<p>Returns whether the NSPanel is a floating panel, e.g. the window level
is NSFloatingWindowLevel instead of NSNormalWindowLevel.</p>
<p>See Also: -setFloatingPanel: </p>
*/
- (BOOL) isFloatingPanel
{
return _isFloatingPanel;
}
/**<p>Sets whether the NSPanel is a floating panel, e.g. the window level
is NSFloatingWindowLevel instead of NSNormalWindowLevel.</p>
<p>See Also: -isFloatingPanel [NSWindow-setLevel:]</p>
*/
- (void) setFloatingPanel: (BOOL)flag
{
if (_isFloatingPanel != flag)
{
_isFloatingPanel = flag;
if (flag == YES)
{
[self setLevel: NSFloatingWindowLevel];
}
else
{
[self setLevel: NSNormalWindowLevel];
}
}
}
/**<p>Returns whether the NSPanel can receive events when another window/panel
runs modally.</p><p>See Also: -setWorksWhenModal:
[NSApplication-runModalSession:]</p>
*/
- (BOOL) worksWhenModal
{
return _worksWhenModal;
}
/**<p>Sets whether the NSPanel can receive events when another window/panel
runs modally.</p>See Also: -worksWhenModal [NSApplication-runModalSession:]
*/
- (void) setWorksWhenModal: (BOOL)flag
{
_worksWhenModal = flag;
}
/**<p>Returns whether if the NSPanel becomes key window only when a view
require to be the first responder.</p>
<p>See Also: -setBecomesKeyOnlyIfNeeded: [NSView-needsPanelToBecomeKey]
[NSWindow-sendEvent:]</p>
*/
- (BOOL) becomesKeyOnlyIfNeeded
{
return _becomesKeyOnlyIfNeeded;
}
/**<p>Sets whether if the NSPanel becomes key window only when a view
require to be the first responder.</p>
<p>See Also: -setBecomesKeyOnlyIfNeeded: [NSView-needsPanelToBecomeKey]
[NSWindow-sendEvent:]</p>
*/
- (void) setBecomesKeyOnlyIfNeeded: (BOOL)flag
{
_becomesKeyOnlyIfNeeded = flag;
}
/*
* NSCoding protocol
*/
- (void) encodeWithCoder: (NSCoder*)aCoder
{
BOOL flag;
[super encodeWithCoder: aCoder];
if ([aCoder allowsKeyedCoding])
{
// Nothing to do here, for keyed coding this is handled by NSWindowTemplate.
// Calling the above method should throw an NSInvalidArgumentException.
}
else
{
flag = _becomesKeyOnlyIfNeeded;
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag];
flag = _isFloatingPanel;
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag];
flag = _worksWhenModal;
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &flag];
}
}
- (id) initWithCoder: (NSCoder*)aDecoder
{
BOOL flag;
self = [super initWithCoder: aDecoder];
if (nil == self)
return nil;
if ([aDecoder allowsKeyedCoding])
{
// Nothing to do here, for keyed coding this is handled by NSWindowTemplate.
// Calling the above method should throw an NSInvalidArgumentException.
}
else
{
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &flag];
[self setBecomesKeyOnlyIfNeeded: flag];
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &flag];
[self setFloatingPanel: flag];
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &flag];
[self setWorksWhenModal: flag];
}
return self;
}
@end /* NSPanel */
2005-01-21 21:43 Alexander Malmberg <alexander@malmberg.org> Various whitespace cleanups, comment type fixes, and changes to avoid warnings from recent versions of gcc. * Headers/Additions/GNUstepGUI/GSToolbar.h (-_toolbars): Declare. * Source/NSWindow+Toolbar.m: Remove conflicting declaration of [NSToolbar -_toolbars]. * Headers/Additions/GNUstepGUI/GSServicesManager.h, Source/GSServicesMananger.m (-item2title:, -validateMenuItem:): Adjust argument types. * Headers/AppKit/NSMenu.h (-validateMenuItem:): Adjust argument type. * Source/NSTextView.m (-sizeToFit): Don't use size uninitialized if neither resizable flags is set. (-insertText:): Adjust argument type. * Headers/AppKit/NSResponder.h, Source/NSResponder.m (-insertText:): Adjust argument type. Document. * Headers/AppKit/NSView.h: Change type of ivar _window to NSWindow *. * Source/GSTitleView.m (-mouseDown:): Always initialize startWindowOrigin. * Source/NSApplication.m (-setApplicationIconImage:): Add casts to avoid warnings. * Source/NSCell.m (-cellSize): Add default: case. * Source/NSPasteboard.m ([GSFiltered -pasteboard:provideDataForType:]): Detect and warn if we can't find a filter that will get us the desired type. * Source/NSProgressIndicator.m: Comment out unused variable 'images'. * Source/NSBezierPath.m: Declare GSBezierPath fully before using it. (-bezierPathByFlatteningPath, -bezierPathByReversingPath): Make sure variables are always initialized. * Source/NSMenuView.m, * Source/NSPrintOperation.m, * Source/NSSplitView.m, * Source/NSTableHeaderView.m: Make sure variables are always initialized. * Source/NSBox.m, * Source/NSImageview.m, * Source/NSText.m, * Source/NSTextStorage.m: Add missing includes. * Source/GSKeyBindingTable.m, * Source/GSLayoutManager.m, * Source/NSBitmapImageRep+PNM.m, * Source/NSBundleAdditions.m, * Source/NSLayoutManager.m, * Source/nsimage-tiff.h, * Source/tiff.m, * Headers/Additions/GNUstepGUI/GSDisplayServer.h, * Source/GSDisplayServer.m: Change signedness of various variables. * Source/NSPanel.m (-sendEvent:): Remove. * Source/NSWindow.m (-becomesKeyOnlyIfNeeded): New method. (-_sendEvent:becomesKeyOnlyIfNeeded:): Remove. Move code ... (-sendEvent:): ... here. Use -becomesKeyOnlyIfNeeded instead of the argument. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@20590 72102866-910b-0410-8b05-ffd578937521
2005-01-21 20:39:18 +00:00