2001-12-17 16:51:51 +00:00
|
|
|
/** <title>NSPanel</title>
|
1996-05-30 20:03:15 +00:00
|
|
|
|
2001-12-17 16:51:51 +00:00
|
|
|
<abstract>Panel window class and related functions</abstract>
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
Copyright (C) 1996 Free Software Foundation, Inc.
|
|
|
|
|
2001-12-17 16:51:51 +00:00
|
|
|
Author: Scott Christley <scottc@net-community.com>
|
1996-05-30 20:03:15 +00:00
|
|
|
Date: 1996
|
1998-12-12 10:03:44 +00:00
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
This file is part of the GNUstep GUI Library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
2007-10-29 21:16:17 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
1996-05-30 20:03:15 +00:00
|
|
|
License as published by the Free Software Foundation; either
|
2008-06-10 04:01:49 +00:00
|
|
|
version 2 of the License, or (at your option) any later version.
|
1998-12-12 10:03:44 +00:00
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2007-10-29 21:16:17 +00:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
1996-05-30 20:03:15 +00:00
|
|
|
|
2007-10-29 21:16:17 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
1996-10-18 17:14:13 +00:00
|
|
|
License along with this library; see the file COPYING.LIB.
|
2007-10-29 21:16:17 +00:00
|
|
|
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.
|
1998-12-12 10:03:44 +00:00
|
|
|
*/
|
1996-05-30 20:03:15 +00:00
|
|
|
|
2010-03-24 22:41:21 +00:00
|
|
|
#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"
|
2000-03-10 18:19:25 +00:00
|
|
|
|
1998-12-10 21:14:52 +00:00
|
|
|
@implementation NSPanel
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1999-11-17 21:54:12 +00:00
|
|
|
/*
|
|
|
|
* Class methods
|
|
|
|
*/
|
1996-05-30 20:03:15 +00:00
|
|
|
+ (void)initialize
|
|
|
|
{
|
2000-03-11 06:57:22 +00:00
|
|
|
if (self == [NSPanel class])
|
1998-12-12 10:03:44 +00:00
|
|
|
{
|
2000-03-11 06:57:22 +00:00
|
|
|
[self setVersion: 1];
|
1998-12-12 10:03:44 +00:00
|
|
|
}
|
2000-03-11 06:57:22 +00:00
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1999-11-17 21:54:12 +00:00
|
|
|
/*
|
|
|
|
* Instance methods
|
|
|
|
*/
|
1998-12-16 15:21:55 +00:00
|
|
|
- (id) init
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
2000-03-11 06:57:22 +00:00
|
|
|
int style = NSTitledWindowMask | NSClosableWindowMask;
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1998-12-12 10:03:44 +00:00
|
|
|
return [self initWithContentRect: NSZeroRect
|
|
|
|
styleMask: style
|
|
|
|
backing: NSBackingStoreBuffered
|
|
|
|
defer: NO];
|
2000-03-11 06:57:22 +00:00
|
|
|
}
|
2013-01-27 20:28:35 +00:00
|
|
|
|
2010-08-04 04:36:53 +00:00
|
|
|
- (id) initWithContentRect: (NSRect)contentRect
|
2013-01-27 20:28:35 +00:00
|
|
|
styleMask: (NSUInteger)aStyle
|
2010-08-04 04:36:53 +00:00
|
|
|
backing: (NSBackingStoreType)bufferingType
|
|
|
|
defer: (BOOL)flag
|
|
|
|
{
|
|
|
|
self = [super initWithContentRect: contentRect
|
|
|
|
styleMask: aStyle
|
|
|
|
backing: bufferingType
|
|
|
|
defer: flag];
|
|
|
|
if (nil == self)
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
2010-08-04 04:36:53 +00:00
|
|
|
if ((_styleMask & NSUtilityWindowMask) == NSUtilityWindowMask)
|
|
|
|
{
|
|
|
|
[self setFloatingPanel: YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
2013-01-27 20:28:35 +00:00
|
|
|
|
2000-03-06 11:39:22 +00:00
|
|
|
- (void) _initDefaults
|
1999-02-16 11:05:22 +00:00
|
|
|
{
|
2000-03-06 11:39:22 +00:00
|
|
|
[super _initDefaults];
|
1999-11-15 21:45:56 +00:00
|
|
|
[self setReleasedWhenClosed: NO];
|
|
|
|
[self setHidesOnDeactivate: YES];
|
|
|
|
[self setExcludedFromWindowsMenu: YES];
|
2000-03-11 06:57:22 +00:00
|
|
|
}
|
1999-02-16 11:05:22 +00:00
|
|
|
|
1998-12-22 12:34:03 +00:00
|
|
|
- (BOOL) canBecomeKeyWindow
|
1999-05-28 14:09:36 +00:00
|
|
|
{
|
|
|
|
return YES;
|
2000-03-11 06:57:22 +00:00
|
|
|
}
|
1999-05-28 14:09:36 +00:00
|
|
|
|
|
|
|
- (BOOL) canBecomeMainWindow
|
1998-12-22 12:34:03 +00:00
|
|
|
{
|
|
|
|
return NO;
|
2000-03-11 06:57:22 +00:00
|
|
|
}
|
1998-12-22 12:34:03 +00:00
|
|
|
|
1999-11-17 21:54:12 +00:00
|
|
|
/*
|
|
|
|
* If we receive an escape, close.
|
|
|
|
*/
|
1998-12-15 16:20:22 +00:00
|
|
|
- (void) keyDown: (NSEvent*)theEvent
|
|
|
|
{
|
2000-03-11 06:57:22 +00:00
|
|
|
if ([@"\e" isEqual: [theEvent charactersIgnoringModifiers]]
|
|
|
|
&& ([self styleMask] & NSClosableWindowMask) == NSClosableWindowMask)
|
1998-12-15 16:20:22 +00:00
|
|
|
[self close];
|
|
|
|
else
|
|
|
|
[super keyDown: theEvent];
|
2000-03-11 06:57:22 +00:00
|
|
|
}
|
1998-12-15 16:20:22 +00:00
|
|
|
|
2005-12-05 15:56:03 +00:00
|
|
|
/**<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>
|
1999-11-17 21:54:12 +00:00
|
|
|
*/
|
1998-12-14 08:58:53 +00:00
|
|
|
- (BOOL) isFloatingPanel
|
|
|
|
{
|
|
|
|
return _isFloatingPanel;
|
2000-03-11 06:57:22 +00:00
|
|
|
}
|
1998-12-14 08:58:53 +00:00
|
|
|
|
2005-12-05 15:56:03 +00:00
|
|
|
/**<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>
|
|
|
|
*/
|
1998-12-14 08:58:53 +00:00
|
|
|
- (void) setFloatingPanel: (BOOL)flag
|
|
|
|
{
|
1999-12-22 06:33:59 +00:00
|
|
|
if (_isFloatingPanel != flag)
|
|
|
|
{
|
|
|
|
_isFloatingPanel = flag;
|
|
|
|
if (flag == YES)
|
|
|
|
{
|
|
|
|
[self setLevel: NSFloatingWindowLevel];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[self setLevel: NSNormalWindowLevel];
|
|
|
|
}
|
|
|
|
}
|
2000-03-11 06:57:22 +00:00
|
|
|
}
|
1998-12-14 08:58:53 +00:00
|
|
|
|
2005-12-05 15:56:03 +00:00
|
|
|
/**<p>Returns whether the NSPanel can receive events when another window/panel
|
|
|
|
runs modally.</p><p>See Also: -setWorksWhenModal:
|
|
|
|
[NSApplication-runModalSession:]</p>
|
|
|
|
*/
|
1998-12-14 08:58:53 +00:00
|
|
|
- (BOOL) worksWhenModal
|
|
|
|
{
|
|
|
|
return _worksWhenModal;
|
2000-03-11 06:57:22 +00:00
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
2005-12-05 15:56:03 +00:00
|
|
|
/**<p>Sets whether the NSPanel can receive events when another window/panel
|
|
|
|
runs modally.</p>See Also: -worksWhenModal [NSApplication-runModalSession:]
|
|
|
|
*/
|
1998-12-14 08:58:53 +00:00
|
|
|
- (void) setWorksWhenModal: (BOOL)flag
|
|
|
|
{
|
2001-09-24 23:30:36 +00:00
|
|
|
_worksWhenModal = flag;
|
2000-03-11 06:57:22 +00:00
|
|
|
}
|
1998-12-14 08:58:53 +00:00
|
|
|
|
2005-12-05 15:56:03 +00:00
|
|
|
/**<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>
|
|
|
|
*/
|
1998-12-14 08:58:53 +00:00
|
|
|
- (BOOL) becomesKeyOnlyIfNeeded
|
|
|
|
{
|
|
|
|
return _becomesKeyOnlyIfNeeded;
|
2000-03-11 06:57:22 +00:00
|
|
|
}
|
1998-12-14 08:58:53 +00:00
|
|
|
|
2005-12-05 15:56:03 +00:00
|
|
|
/**<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>
|
|
|
|
*/
|
1999-11-15 21:45:56 +00:00
|
|
|
- (void) setBecomesKeyOnlyIfNeeded: (BOOL)flag
|
1998-08-19 09:00:26 +00:00
|
|
|
{
|
2001-09-24 23:30:36 +00:00
|
|
|
_becomesKeyOnlyIfNeeded = flag;
|
2000-03-11 06:57:22 +00:00
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1999-11-17 21:54:12 +00:00
|
|
|
/*
|
|
|
|
* NSCoding protocol
|
|
|
|
*/
|
1998-12-14 08:58:53 +00:00
|
|
|
- (void) encodeWithCoder: (NSCoder*)aCoder
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
2001-09-24 23:30:36 +00:00
|
|
|
BOOL flag;
|
|
|
|
|
1999-03-02 08:58:30 +00:00
|
|
|
[super encodeWithCoder: aCoder];
|
2006-10-15 08:34:47 +00:00
|
|
|
if ([aCoder allowsKeyedCoding])
|
2006-06-04 05:16:37 +00:00
|
|
|
{
|
|
|
|
// 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];
|
|
|
|
}
|
2000-03-11 06:57:22 +00:00
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1999-03-02 08:58:30 +00:00
|
|
|
- (id) initWithCoder: (NSCoder*)aDecoder
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
2001-09-24 23:30:36 +00:00
|
|
|
BOOL flag;
|
|
|
|
|
2011-03-14 22:59:20 +00:00
|
|
|
self = [super initWithCoder: aDecoder];
|
|
|
|
if (nil == self)
|
|
|
|
return nil;
|
|
|
|
|
2006-10-15 08:34:47 +00:00
|
|
|
if ([aDecoder allowsKeyedCoding])
|
2006-06-04 05:16:37 +00:00
|
|
|
{
|
|
|
|
// 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];
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1998-12-14 08:58:53 +00:00
|
|
|
return self;
|
2000-03-11 06:57:22 +00:00
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1998-12-10 21:14:52 +00:00
|
|
|
@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
|
|
|
|