2004-01-11 18:48:18 +00:00
|
|
|
/** <title>GSTitleView</title>
|
|
|
|
|
|
|
|
Copyright (C) 2003 Free Software Foundation, Inc.
|
|
|
|
|
2020-01-31 00:31:19 +00:00
|
|
|
Author: Sergii Stoian <stoyan255@gmail.com>
|
2004-01-15 15:57:00 +00:00
|
|
|
Date: Mar 2003
|
2004-01-11 18:48:18 +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
|
2004-01-11 18:48:18 +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.
|
2007-10-29 21:16:17 +00:00
|
|
|
|
2004-01-11 18:48:18 +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.
|
2004-01-11 18:48:18 +00:00
|
|
|
|
2007-10-29 21:16:17 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2004-01-11 18:48:18 +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.
|
2004-01-11 18:48:18 +00:00
|
|
|
*/
|
|
|
|
|
2010-03-25 21:30:28 +00:00
|
|
|
#import <Foundation/NSDebug.h>
|
|
|
|
#import <Foundation/NSNotification.h>
|
|
|
|
#import <Foundation/NSRunLoop.h>
|
|
|
|
|
|
|
|
#import "AppKit/NSApplication.h"
|
|
|
|
#import "AppKit/NSAttributedString.h"
|
|
|
|
#import "AppKit/NSButton.h"
|
|
|
|
#import "AppKit/NSColor.h"
|
|
|
|
#import "AppKit/NSEvent.h"
|
|
|
|
#import "AppKit/NSGraphics.h"
|
|
|
|
#import "AppKit/NSImage.h"
|
|
|
|
#import "AppKit/NSMenu.h"
|
|
|
|
#import "AppKit/NSMenuView.h"
|
|
|
|
#import "AppKit/NSPanel.h"
|
2010-03-31 08:14:50 +00:00
|
|
|
#import "AppKit/NSStringDrawing.h"
|
2010-03-25 21:30:28 +00:00
|
|
|
#import "AppKit/NSView.h"
|
|
|
|
#import "AppKit/NSWindow.h"
|
2020-01-31 00:31:19 +00:00
|
|
|
#import "AppKit/NSScreen.h"
|
2010-03-25 21:30:28 +00:00
|
|
|
|
|
|
|
#import "GNUstepGUI/GSTitleView.h"
|
|
|
|
#import "GNUstepGUI/GSTheme.h"
|
2004-06-07 23:54:25 +00:00
|
|
|
|
2004-01-11 18:48:18 +00:00
|
|
|
@implementation GSTitleView
|
|
|
|
|
2004-01-15 15:57:00 +00:00
|
|
|
// ============================================================================
|
|
|
|
// ==== Initialization & deallocation
|
|
|
|
// ============================================================================
|
|
|
|
|
2004-01-11 18:48:18 +00:00
|
|
|
+ (float) height
|
|
|
|
{
|
2009-05-01 22:54:11 +00:00
|
|
|
return [NSMenuView menuBarHeight] + 1;
|
2004-01-11 18:48:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
self = [super init];
|
2009-05-01 22:54:11 +00:00
|
|
|
if (!self)
|
|
|
|
return nil;
|
2004-01-11 18:48:18 +00:00
|
|
|
|
|
|
|
_owner = nil;
|
|
|
|
_ownedByMenu = NO;
|
2004-01-15 15:57:00 +00:00
|
|
|
_isKeyWindow = NO;
|
|
|
|
_isMainWindow = NO;
|
|
|
|
_isActiveApplication = NO;
|
2004-01-11 18:48:18 +00:00
|
|
|
|
|
|
|
[self setAutoresizingMask: NSViewWidthSizable | NSViewMinYMargin];
|
|
|
|
|
|
|
|
textAttributes = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
|
|
|
|
[NSFont boldSystemFontOfSize: 0], NSFontAttributeName,
|
2004-01-15 15:57:00 +00:00
|
|
|
[NSColor blackColor], NSForegroundColorAttributeName, nil];
|
2004-01-11 18:48:18 +00:00
|
|
|
|
|
|
|
titleColor = RETAIN ([NSColor lightGrayColor]);
|
|
|
|
|
2004-01-15 15:57:00 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) initWithOwner: (id)owner
|
|
|
|
{
|
2009-05-01 22:54:11 +00:00
|
|
|
self = [self init];
|
|
|
|
if (!self)
|
|
|
|
return nil;
|
|
|
|
|
2004-01-15 15:57:00 +00:00
|
|
|
[self setOwner: owner];
|
2004-01-11 18:48:18 +00:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2004-01-15 15:57:00 +00:00
|
|
|
- (void) setOwner: (id)owner
|
|
|
|
{
|
|
|
|
NSNotificationCenter *theCenter = [NSNotificationCenter defaultCenter];
|
|
|
|
|
2009-05-01 22:54:11 +00:00
|
|
|
if ([owner isKindOfClass: [NSWindow class]])
|
2004-01-15 15:57:00 +00:00
|
|
|
{
|
|
|
|
NSDebugLLog(@"GSTitleView", @"owner is NSWindow or NSPanel");
|
|
|
|
_owner = owner;
|
|
|
|
_ownedByMenu = NO;
|
|
|
|
|
|
|
|
[self setFrame:
|
|
|
|
NSMakeRect (-1, [_owner frame].size.height - [GSTitleView height]-40,
|
|
|
|
[_owner frame].size.width+2, [GSTitleView height])];
|
|
|
|
|
|
|
|
if ([_owner styleMask] & NSClosableWindowMask)
|
2009-05-01 22:54:11 +00:00
|
|
|
{
|
|
|
|
[self addCloseButtonWithAction: @selector(performClose:)];
|
|
|
|
}
|
2004-01-15 15:57:00 +00:00
|
|
|
if ([_owner styleMask] & NSMiniaturizableWindowMask)
|
2009-05-01 22:54:11 +00:00
|
|
|
{
|
|
|
|
[self addMiniaturizeButtonWithAction: @selector(performMiniaturize:)];
|
|
|
|
}
|
2004-01-15 15:57:00 +00:00
|
|
|
|
|
|
|
// NSWindow observers
|
|
|
|
[theCenter addObserver: self
|
|
|
|
selector: @selector(windowBecomeKey:)
|
|
|
|
name: NSWindowDidBecomeKeyNotification
|
|
|
|
object: _owner];
|
|
|
|
[theCenter addObserver: self
|
|
|
|
selector: @selector(windowResignKey:)
|
|
|
|
name: NSWindowDidResignKeyNotification
|
|
|
|
object: _owner];
|
|
|
|
[theCenter addObserver: self
|
|
|
|
selector: @selector(windowBecomeMain:)
|
|
|
|
name: NSWindowDidBecomeMainNotification
|
|
|
|
object: _owner];
|
|
|
|
[theCenter addObserver: self
|
|
|
|
selector: @selector(windowResignMain:)
|
|
|
|
name: NSWindowDidResignMainNotification
|
|
|
|
object: _owner];
|
|
|
|
|
|
|
|
// NSApplication observers
|
|
|
|
[theCenter addObserver: self
|
|
|
|
selector: @selector(applicationBecomeActive:)
|
|
|
|
name: NSApplicationWillBecomeActiveNotification
|
|
|
|
object: NSApp];
|
|
|
|
[theCenter addObserver: self
|
|
|
|
selector: @selector(applicationResignActive:)
|
|
|
|
name: NSApplicationWillResignActiveNotification
|
|
|
|
object: NSApp];
|
|
|
|
}
|
2009-05-01 22:54:11 +00:00
|
|
|
else if ([owner isKindOfClass: [NSMenu class]])
|
2004-01-15 15:57:00 +00:00
|
|
|
{
|
2010-02-25 23:13:08 +00:00
|
|
|
NSColor *textColor;
|
|
|
|
GSTheme *theme;
|
|
|
|
|
2004-01-15 15:57:00 +00:00
|
|
|
NSDebugLLog(@"GSTitleView", @"owner is NSMenu");
|
|
|
|
_owner = owner;
|
|
|
|
_ownedByMenu = YES;
|
2010-02-25 23:13:08 +00:00
|
|
|
theme = [GSTheme theme];
|
2004-01-15 15:57:00 +00:00
|
|
|
|
|
|
|
RELEASE (titleColor);
|
2010-02-12 17:56:11 +00:00
|
|
|
titleColor = RETAIN ([theme colorNamed: @"GSMenuBar" state: GSThemeNormalState]);
|
|
|
|
if (titleColor == nil)
|
|
|
|
{
|
|
|
|
titleColor = RETAIN ([NSColor blackColor]);
|
|
|
|
}
|
|
|
|
|
|
|
|
textColor = [theme colorNamed: @"GSMenuBarTitle" state: GSThemeNormalState];
|
|
|
|
if (textColor == nil)
|
|
|
|
{
|
|
|
|
textColor = [NSColor whiteColor];
|
|
|
|
}
|
|
|
|
[textAttributes setObject: textColor
|
|
|
|
forKey: NSForegroundColorAttributeName];
|
2004-01-15 15:57:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSDebugLLog(@"GSTitleView",
|
|
|
|
@"%@ owner is not NSMenu or NSWindow or NSPanel",
|
|
|
|
[owner className]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) owner
|
|
|
|
{
|
|
|
|
return _owner;
|
|
|
|
}
|
|
|
|
|
2004-01-11 18:48:18 +00:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
2004-01-15 15:57:00 +00:00
|
|
|
if (!_ownedByMenu)
|
|
|
|
{
|
2009-05-01 22:54:11 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
2004-01-15 15:57:00 +00:00
|
|
|
}
|
|
|
|
|
2009-05-01 22:54:11 +00:00
|
|
|
RELEASE(textAttributes);
|
|
|
|
RELEASE(titleColor);
|
2013-10-07 06:23:02 +00:00
|
|
|
[[GSTheme theme] setName: nil forElement: [closeButton cell] temporary: NO];
|
2009-05-01 22:54:11 +00:00
|
|
|
TEST_RELEASE(closeButton);
|
|
|
|
TEST_RELEASE(miniaturizeButton);
|
2004-01-11 18:48:18 +00:00
|
|
|
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2004-01-15 15:57:00 +00:00
|
|
|
// ============================================================================
|
|
|
|
// ==== Drawing
|
|
|
|
// ============================================================================
|
|
|
|
|
2004-01-11 18:48:18 +00:00
|
|
|
- (NSSize) titleSize
|
|
|
|
{
|
|
|
|
return [[_owner title] sizeWithAttributes: textAttributes];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) drawRect: (NSRect)rect
|
|
|
|
{
|
2013-09-29 00:30:59 +00:00
|
|
|
NSRect workRect = [[GSTheme theme] drawMenuTitleBackground: self
|
|
|
|
withBounds: [self bounds]
|
|
|
|
withClip: rect];
|
2004-01-11 18:48:18 +00:00
|
|
|
// Draw the title
|
2013-09-29 00:30:59 +00:00
|
|
|
NSSize titleSize = [self titleSize];
|
|
|
|
workRect.origin.x += 4;
|
|
|
|
|
2004-01-11 18:48:18 +00:00
|
|
|
workRect.origin.y = NSMidY (workRect) - titleSize.height / 2;
|
|
|
|
workRect.size.height = titleSize.height;
|
|
|
|
[[_owner title] drawInRect: workRect withAttributes: textAttributes];
|
|
|
|
}
|
|
|
|
|
2004-01-15 15:57:00 +00:00
|
|
|
// ============================================================================
|
|
|
|
// ==== Mouse actions
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
- (BOOL) acceptsFirstMouse: (NSEvent *)theEvent
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2004-01-11 18:48:18 +00:00
|
|
|
- (void) mouseDown: (NSEvent*)theEvent
|
|
|
|
{
|
|
|
|
NSPoint lastLocation;
|
|
|
|
NSPoint location;
|
2013-02-13 08:40:36 +00:00
|
|
|
NSUInteger eventMask = NSLeftMouseUpMask | NSPeriodicMask;
|
2004-01-11 18:48:18 +00:00
|
|
|
BOOL done = NO;
|
2005-02-14 10:35:39 +00:00
|
|
|
BOOL moved = NO;
|
2004-01-11 18:48:18 +00:00
|
|
|
NSDate *theDistantFuture = [NSDate distantFuture];
|
2004-01-11 21:55:06 +00:00
|
|
|
NSPoint startWindowOrigin;
|
|
|
|
NSPoint endWindowOrigin;
|
2020-02-03 00:22:27 +00:00
|
|
|
NSRect screenFrame = NSZeroRect;
|
|
|
|
CGFloat leftLimit = -1.0;
|
|
|
|
CGFloat topLimit = -1.0 ;
|
|
|
|
CGFloat rightLimit = -1.0;
|
|
|
|
CGFloat bottomLimit = 0.0;
|
2004-01-11 18:48:18 +00:00
|
|
|
|
|
|
|
NSDebugLLog (@"NSMenu", @"Mouse down in title!");
|
|
|
|
|
2020-01-31 00:31:19 +00:00
|
|
|
// Define move constrains for menu
|
|
|
|
if (_ownedByMenu)
|
|
|
|
{
|
2020-02-03 00:22:27 +00:00
|
|
|
NSRect windowFrame;
|
|
|
|
NSScreen *screen;
|
|
|
|
|
|
|
|
if (_window && (screen = [_window screen]))
|
|
|
|
{
|
|
|
|
windowFrame = [_window frame];
|
|
|
|
screenFrame = [screen frame];
|
|
|
|
leftLimit = screenFrame.origin.x;
|
|
|
|
topLimit = NSMaxY(screenFrame) - windowFrame.size.height;
|
|
|
|
rightLimit = NSMaxX(screenFrame) - windowFrame.size.width;
|
|
|
|
bottomLimit = screenFrame.origin.y -
|
|
|
|
(windowFrame.size.height - [self frame].size.height);
|
|
|
|
}
|
2020-01-31 00:31:19 +00:00
|
|
|
}
|
|
|
|
|
2004-01-11 21:55:06 +00:00
|
|
|
// Remember start position of window
|
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
|
|
|
startWindowOrigin = [_window frame].origin;
|
2004-01-11 18:48:18 +00:00
|
|
|
|
2004-01-11 21:55:06 +00:00
|
|
|
// Remember start location of cursor in window
|
|
|
|
lastLocation = [theEvent locationInWindow];
|
|
|
|
|
2004-01-11 18:48:18 +00:00
|
|
|
[_window _captureMouse: nil];
|
|
|
|
|
|
|
|
[NSEvent startPeriodicEventsAfterDelay: 0.02 withPeriod: 0.02];
|
|
|
|
|
|
|
|
while (!done)
|
|
|
|
{
|
|
|
|
theEvent = [NSApp nextEventMatchingMask: eventMask
|
|
|
|
untilDate: theDistantFuture
|
|
|
|
inMode: NSEventTrackingRunLoopMode
|
|
|
|
dequeue: YES];
|
|
|
|
switch ([theEvent type])
|
|
|
|
{
|
|
|
|
case NSRightMouseUp:
|
|
|
|
case NSLeftMouseUp:
|
|
|
|
done = YES;
|
|
|
|
[_window _releaseMouse: nil];
|
|
|
|
break;
|
|
|
|
case NSPeriodic:
|
|
|
|
location = [_window mouseLocationOutsideOfEventStream];
|
|
|
|
if (NSEqualPoints(location, lastLocation) == NO)
|
|
|
|
{
|
|
|
|
NSPoint origin = [_window frame].origin;
|
|
|
|
|
2009-05-01 22:54:11 +00:00
|
|
|
moved = YES;
|
2004-01-11 18:48:18 +00:00
|
|
|
origin.x += (location.x - lastLocation.x);
|
|
|
|
origin.y += (location.y - lastLocation.y);
|
2009-05-01 22:54:11 +00:00
|
|
|
if (_ownedByMenu)
|
|
|
|
{
|
2020-02-03 00:22:27 +00:00
|
|
|
if (screenFrame.size.width > 0 && screenFrame.size.height > 0)
|
|
|
|
{
|
|
|
|
if (origin.x <= leftLimit)
|
|
|
|
origin.x = leftLimit;
|
|
|
|
else if (origin.x >= rightLimit)
|
|
|
|
origin.x = rightLimit;
|
|
|
|
|
|
|
|
if (origin.y >= topLimit)
|
|
|
|
origin.y = topLimit;
|
|
|
|
else if (origin.y <= bottomLimit)
|
|
|
|
origin.y = bottomLimit;
|
|
|
|
}
|
2020-01-31 00:31:19 +00:00
|
|
|
|
2009-05-01 22:54:11 +00:00
|
|
|
[_owner nestedSetFrameOrigin: origin];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[_owner setFrameOrigin: origin];
|
|
|
|
}
|
2004-01-11 18:48:18 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-01-11 21:55:06 +00:00
|
|
|
|
|
|
|
// Make menu torn off
|
|
|
|
if (_ownedByMenu && ![_owner isTornOff] && [_owner supermenu])
|
|
|
|
{
|
|
|
|
endWindowOrigin = [_window frame].origin;
|
|
|
|
if ((startWindowOrigin.x != endWindowOrigin.x
|
|
|
|
|| startWindowOrigin.y != endWindowOrigin.y))
|
2009-05-01 22:54:11 +00:00
|
|
|
{
|
|
|
|
[_owner setTornOff: YES];
|
|
|
|
}
|
2004-01-11 21:55:06 +00:00
|
|
|
}
|
|
|
|
|
2004-01-11 18:48:18 +00:00
|
|
|
[NSEvent stopPeriodicEvents];
|
2005-02-14 10:35:39 +00:00
|
|
|
|
|
|
|
if (moved == YES)
|
|
|
|
{
|
|
|
|
// Let everything know the window has moved.
|
|
|
|
[[NSNotificationCenter defaultCenter]
|
2009-05-01 22:54:11 +00:00
|
|
|
postNotificationName: NSWindowDidMoveNotification object: _window];
|
2005-02-14 10:35:39 +00:00
|
|
|
}
|
2004-01-11 18:48:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// We do not need app menu over menu
|
2005-10-20 18:39:21 +00:00
|
|
|
- (void) rightMouseDown: (NSEvent*)theEvent
|
2004-01-11 18:48:18 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// We do not want to popup menus in this menu.
|
2005-10-20 18:39:21 +00:00
|
|
|
- (NSMenu *) menuForEvent: (NSEvent*) theEvent
|
2004-01-11 18:48:18 +00:00
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2004-01-15 15:57:00 +00:00
|
|
|
// ============================================================================
|
|
|
|
// ==== NSWindow & NSApplication notifications
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
- (void) applicationBecomeActive: (NSNotification *)notification
|
|
|
|
{
|
|
|
|
_isActiveApplication = YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) applicationResignActive: (NSNotification *)notification
|
|
|
|
{
|
|
|
|
_isActiveApplication = NO;
|
|
|
|
RELEASE (titleColor);
|
|
|
|
titleColor = RETAIN ([NSColor lightGrayColor]);
|
|
|
|
[textAttributes setObject: [NSColor blackColor]
|
|
|
|
forKey: NSForegroundColorAttributeName];
|
|
|
|
[self setNeedsDisplay: YES];
|
|
|
|
}
|
|
|
|
|
2004-01-11 18:48:18 +00:00
|
|
|
- (void) windowBecomeKey: (NSNotification *)notification
|
|
|
|
{
|
2004-01-15 15:57:00 +00:00
|
|
|
_isKeyWindow = YES;
|
2004-01-11 18:48:18 +00:00
|
|
|
RELEASE (titleColor);
|
|
|
|
titleColor = RETAIN ([NSColor blackColor]);
|
|
|
|
[textAttributes setObject: [NSColor whiteColor]
|
|
|
|
forKey: NSForegroundColorAttributeName];
|
|
|
|
|
|
|
|
[self setNeedsDisplay: YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) windowResignKey: (NSNotification *)notification
|
|
|
|
{
|
2004-01-15 15:57:00 +00:00
|
|
|
_isKeyWindow = NO;
|
2004-01-11 18:48:18 +00:00
|
|
|
RELEASE (titleColor);
|
2004-01-15 15:57:00 +00:00
|
|
|
if (_isActiveApplication && _isMainWindow)
|
2004-01-11 18:48:18 +00:00
|
|
|
{
|
|
|
|
titleColor = RETAIN ([NSColor darkGrayColor]);
|
|
|
|
[textAttributes setObject: [NSColor whiteColor]
|
|
|
|
forKey: NSForegroundColorAttributeName];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
titleColor = RETAIN ([NSColor lightGrayColor]);
|
|
|
|
[textAttributes setObject: [NSColor blackColor]
|
|
|
|
forKey: NSForegroundColorAttributeName];
|
|
|
|
}
|
|
|
|
[self setNeedsDisplay: YES];
|
|
|
|
}
|
|
|
|
|
2004-01-15 15:57:00 +00:00
|
|
|
- (void) windowBecomeMain: (NSNotification *)notification
|
|
|
|
{
|
|
|
|
_isMainWindow = YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) windowResignMain: (NSNotification *)notification
|
|
|
|
{
|
|
|
|
_isMainWindow = NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// ==== Buttons
|
|
|
|
// ============================================================================
|
|
|
|
|
2004-01-11 18:48:18 +00:00
|
|
|
- (void) addCloseButtonWithAction: (SEL)closeAction
|
|
|
|
{
|
|
|
|
if (closeButton == nil)
|
|
|
|
{
|
2013-10-07 06:23:02 +00:00
|
|
|
[[GSTheme theme] setName: nil forElement: [closeButton cell] temporary: NO];
|
2009-05-01 22:54:11 +00:00
|
|
|
ASSIGN(closeButton,
|
|
|
|
[NSWindow standardWindowButton:
|
|
|
|
NSWindowCloseButton
|
|
|
|
forStyleMask:
|
|
|
|
NSTitledWindowMask | NSClosableWindowMask
|
|
|
|
| NSMiniaturizableWindowMask]);
|
2013-10-07 06:23:02 +00:00
|
|
|
[[GSTheme theme] setName: @"GSMenuCloseButton" forElement: [closeButton cell] temporary: NO];
|
2009-05-01 22:54:11 +00:00
|
|
|
|
|
|
|
[closeButton setTarget: _owner];
|
|
|
|
[closeButton setAction: closeAction];
|
2004-01-11 18:48:18 +00:00
|
|
|
|
|
|
|
// Update location
|
2023-09-22 05:42:47 +00:00
|
|
|
[[GSTheme theme] setFrameForCloseButton: closeButton
|
|
|
|
viewSize: [self frame].size];
|
2004-01-11 18:48:18 +00:00
|
|
|
|
|
|
|
[closeButton setAutoresizingMask: NSViewMinXMargin | NSViewMaxYMargin];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([closeButton superview] == nil)
|
|
|
|
{
|
|
|
|
[self addSubview: closeButton];
|
|
|
|
[self setNeedsDisplay: YES];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-15 15:57:00 +00:00
|
|
|
- (NSButton *) closeButton
|
|
|
|
{
|
|
|
|
return closeButton;
|
|
|
|
}
|
|
|
|
|
2004-01-11 18:48:18 +00:00
|
|
|
- (void) removeCloseButton
|
|
|
|
{
|
|
|
|
if ([closeButton superview] != nil)
|
|
|
|
{
|
|
|
|
[closeButton removeFromSuperview];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) addMiniaturizeButtonWithAction: (SEL)miniaturizeAction
|
|
|
|
{
|
|
|
|
if (miniaturizeButton == nil)
|
|
|
|
{
|
2004-02-05 20:07:42 +00:00
|
|
|
NSSize viewSize;
|
|
|
|
NSSize buttonSize;
|
2004-01-11 18:48:18 +00:00
|
|
|
|
2009-05-01 22:54:11 +00:00
|
|
|
ASSIGN(miniaturizeButton,
|
|
|
|
[NSWindow standardWindowButton:
|
|
|
|
NSWindowMiniaturizeButton
|
|
|
|
forStyleMask:
|
|
|
|
NSTitledWindowMask | NSClosableWindowMask
|
|
|
|
| NSMiniaturizableWindowMask]);
|
|
|
|
[miniaturizeButton setTarget: _owner];
|
|
|
|
[miniaturizeButton setAction: miniaturizeAction];
|
2004-02-05 20:07:42 +00:00
|
|
|
|
|
|
|
viewSize = [self frame].size;
|
2009-05-01 22:54:11 +00:00
|
|
|
buttonSize = [[miniaturizeButton image] size];
|
|
|
|
buttonSize = NSMakeSize(buttonSize.width + 3, buttonSize.height + 3);
|
2004-01-11 18:48:18 +00:00
|
|
|
|
|
|
|
// Update location
|
2009-05-01 22:54:11 +00:00
|
|
|
[miniaturizeButton setFrame:
|
|
|
|
NSMakeRect(4, (viewSize.height - buttonSize.height) / 2,
|
|
|
|
buttonSize.width, buttonSize.height)];
|
2004-01-11 18:48:18 +00:00
|
|
|
|
2009-05-01 22:54:11 +00:00
|
|
|
[miniaturizeButton setAutoresizingMask: NSViewMaxXMargin | NSViewMaxYMargin];
|
2004-01-11 18:48:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ([miniaturizeButton superview] == nil)
|
|
|
|
{
|
|
|
|
[self addSubview: miniaturizeButton];
|
|
|
|
[self setNeedsDisplay: YES];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-15 15:57:00 +00:00
|
|
|
- (NSButton *) miniaturizeButton
|
|
|
|
{
|
|
|
|
return miniaturizeButton;
|
|
|
|
}
|
|
|
|
|
2004-01-11 18:48:18 +00:00
|
|
|
- (void) removeMiniaturizeButton
|
|
|
|
{
|
|
|
|
if ([miniaturizeButton superview] != nil)
|
|
|
|
{
|
|
|
|
[miniaturizeButton removeFromSuperview];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|