mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 20:40:47 +00:00
Some methods added. Cleanup
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@18420 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
f9fb42c964
commit
e8345fbb38
1 changed files with 195 additions and 83 deletions
|
@ -3,7 +3,7 @@
|
||||||
Copyright (C) 2003 Free Software Foundation, Inc.
|
Copyright (C) 2003 Free Software Foundation, Inc.
|
||||||
|
|
||||||
Author: Serg Stoyan <stoyan@on.com.ua>
|
Author: Serg Stoyan <stoyan@on.com.ua>
|
||||||
Date: Mar 2003
|
Date: Mar 2003
|
||||||
|
|
||||||
This file is part of the GNUstep GUI Library.
|
This file is part of the GNUstep GUI Library.
|
||||||
|
|
||||||
|
@ -39,6 +39,10 @@
|
||||||
|
|
||||||
@implementation GSTitleView
|
@implementation GSTitleView
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// ==== Initialization & deallocation
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
+ (float) height
|
+ (float) height
|
||||||
{
|
{
|
||||||
static float height = 0.0;
|
static float height = 0.0;
|
||||||
|
@ -66,34 +70,122 @@
|
||||||
_ownedByMenu = NO;
|
_ownedByMenu = NO;
|
||||||
_hasCloseButton = NO;
|
_hasCloseButton = NO;
|
||||||
_hasMiniaturizeButton = NO;
|
_hasMiniaturizeButton = NO;
|
||||||
|
_isKeyWindow = NO;
|
||||||
|
_isMainWindow = NO;
|
||||||
|
_isActiveApplication = NO;
|
||||||
|
|
||||||
[self setAutoresizingMask: NSViewWidthSizable | NSViewMinYMargin];
|
[self setAutoresizingMask: NSViewWidthSizable | NSViewMinYMargin];
|
||||||
|
|
||||||
textAttributes = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
|
textAttributes = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
|
||||||
[NSFont boldSystemFontOfSize: 0], NSFontAttributeName,
|
[NSFont boldSystemFontOfSize: 0], NSFontAttributeName,
|
||||||
[NSColor blackColor], NSForegroundColorAttributeName, nil];
|
[NSColor blackColor], NSForegroundColorAttributeName, nil];
|
||||||
|
|
||||||
titleColor = RETAIN ([NSColor lightGrayColor]);
|
titleColor = RETAIN ([NSColor lightGrayColor]);
|
||||||
|
|
||||||
/* [self setAutoresizingMask:
|
|
||||||
NSViewMinXMargin | NSViewMinYMargin | NSViewMaxYMargin];*/
|
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (id) initWithOwner: (id)owner
|
||||||
|
{
|
||||||
|
[self init];
|
||||||
|
[self setOwner: owner];
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) setOwner: (id)owner
|
||||||
|
{
|
||||||
|
NSNotificationCenter *theCenter = [NSNotificationCenter defaultCenter];
|
||||||
|
|
||||||
|
if ([owner isKindOfClass:[NSWindow class]])
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
[self addCloseButtonWithAction:@selector (performClose:)];
|
||||||
|
}
|
||||||
|
if ([_owner styleMask] & NSMiniaturizableWindowMask)
|
||||||
|
{
|
||||||
|
[self addMiniaturizeButtonWithAction:@selector (performMiniaturize:)];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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];
|
||||||
|
}
|
||||||
|
else if ([owner isKindOfClass:[NSMenu class]])
|
||||||
|
{
|
||||||
|
NSDebugLLog(@"GSTitleView", @"owner is NSMenu");
|
||||||
|
_owner = owner;
|
||||||
|
_ownedByMenu = YES;
|
||||||
|
|
||||||
|
RELEASE (titleColor);
|
||||||
|
titleColor = RETAIN ([NSColor blackColor]);
|
||||||
|
[textAttributes setObject: [NSColor whiteColor]
|
||||||
|
forKey: NSForegroundColorAttributeName];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NSDebugLLog(@"GSTitleView",
|
||||||
|
@"%@ owner is not NSMenu or NSWindow or NSPanel",
|
||||||
|
[owner className]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (id) owner
|
||||||
|
{
|
||||||
|
return _owner;
|
||||||
|
}
|
||||||
|
|
||||||
- (void) dealloc
|
- (void) dealloc
|
||||||
{
|
{
|
||||||
RELEASE (closeButton);
|
if (!_ownedByMenu)
|
||||||
RELEASE (miniaturizeButton);
|
{
|
||||||
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||||
|
}
|
||||||
|
|
||||||
|
RELEASE (textAttributes);
|
||||||
|
RELEASE (titleColor);
|
||||||
|
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) acceptsFirstMouse: (NSEvent *)theEvent
|
// ============================================================================
|
||||||
{
|
// ==== Drawing
|
||||||
return YES;
|
// ============================================================================
|
||||||
}
|
|
||||||
|
|
||||||
- (NSSize) titleSize
|
- (NSSize) titleSize
|
||||||
{
|
{
|
||||||
return [[_owner title] sizeWithAttributes: textAttributes];
|
return [[_owner title] sizeWithAttributes: textAttributes];
|
||||||
|
@ -103,27 +195,52 @@
|
||||||
{
|
{
|
||||||
NSRect workRect = [self bounds];
|
NSRect workRect = [self bounds];
|
||||||
NSSize titleSize;
|
NSSize titleSize;
|
||||||
NSRectEdge sides[] = {NSMinXEdge, NSMaxYEdge};
|
NSRectEdge top_left[] = {NSMinXEdge, NSMaxYEdge};
|
||||||
|
NSRectEdge bottom_right[] = {NSMaxXEdge, NSMinYEdge};
|
||||||
float blacks[] = {NSBlack, NSBlack};
|
float blacks[] = {NSBlack, NSBlack};
|
||||||
float grays[] = {NSDarkGray, NSDarkGray};
|
float grays[] = {NSLightGray, NSLightGray};
|
||||||
|
float darkGrays[] = {NSDarkGray, NSDarkGray};
|
||||||
|
|
||||||
// Draw the dark gray upper left lines.
|
// Draw the dark gray upper left lines for menu and black for others.
|
||||||
|
// Rectangle 1
|
||||||
if (_ownedByMenu)
|
if (_ownedByMenu)
|
||||||
workRect = NSDrawTiledRects(workRect, workRect, sides, grays, 2);
|
workRect = NSDrawTiledRects(workRect, workRect, top_left, darkGrays, 2);
|
||||||
else
|
else
|
||||||
workRect = NSDrawTiledRects(workRect, workRect, sides, blacks, 2);
|
workRect = NSDrawTiledRects(workRect, workRect, top_left, blacks, 2);
|
||||||
|
|
||||||
|
|
||||||
|
// Rectangle 2
|
||||||
// Draw the title box's button.
|
// Draw the title box's button.
|
||||||
NSDrawButton(workRect, workRect);
|
NSDrawButton(workRect, workRect);
|
||||||
|
|
||||||
// Paint it Black!
|
// Overdraw white top and left lines with light gray lines for window title
|
||||||
|
workRect.origin.y += 1;
|
||||||
|
workRect.size.height -= 1;
|
||||||
|
workRect.size.width -= 1;
|
||||||
|
if (!_ownedByMenu && (_isKeyWindow || _isMainWindow))
|
||||||
|
{
|
||||||
|
NSDrawTiledRects(workRect, workRect, top_left, grays, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rectangle 3
|
||||||
|
// Paint background
|
||||||
workRect.origin.x += 1;
|
workRect.origin.x += 1;
|
||||||
workRect.origin.y += 2;
|
workRect.origin.y += 1;
|
||||||
workRect.size.height -= 3;
|
workRect.size.height -= 2;
|
||||||
workRect.size.width -= 3;
|
workRect.size.width -= 2;
|
||||||
|
|
||||||
[titleColor set];
|
[titleColor set];
|
||||||
NSRectFill(workRect);
|
NSRectFill(workRect);
|
||||||
|
|
||||||
|
if (!_ownedByMenu && _isMainWindow && !_isKeyWindow)
|
||||||
|
{
|
||||||
|
NSRect blRect = workRect;
|
||||||
|
|
||||||
|
blRect.origin.y -= 1;
|
||||||
|
blRect.size.width += 1;
|
||||||
|
blRect.size.height += 1;
|
||||||
|
NSDrawTiledRects(blRect, blRect, bottom_right, blacks, 2);
|
||||||
|
}
|
||||||
|
|
||||||
// Draw the title
|
// Draw the title
|
||||||
titleSize = [self titleSize];
|
titleSize = [self titleSize];
|
||||||
|
@ -140,6 +257,15 @@
|
||||||
[[_owner title] drawInRect: workRect withAttributes: textAttributes];
|
[[_owner title] drawInRect: workRect withAttributes: textAttributes];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// ==== Mouse actions
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
|
- (BOOL) acceptsFirstMouse: (NSEvent *)theEvent
|
||||||
|
{
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
- (void) mouseDown: (NSEvent*)theEvent
|
- (void) mouseDown: (NSEvent*)theEvent
|
||||||
{
|
{
|
||||||
NSPoint lastLocation;
|
NSPoint lastLocation;
|
||||||
|
@ -227,8 +353,28 @@
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// ==== 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];
|
||||||
|
}
|
||||||
|
|
||||||
- (void) windowBecomeKey: (NSNotification *)notification
|
- (void) windowBecomeKey: (NSNotification *)notification
|
||||||
{
|
{
|
||||||
|
_isKeyWindow = YES;
|
||||||
RELEASE (titleColor);
|
RELEASE (titleColor);
|
||||||
titleColor = RETAIN ([NSColor blackColor]);
|
titleColor = RETAIN ([NSColor blackColor]);
|
||||||
[textAttributes setObject: [NSColor whiteColor]
|
[textAttributes setObject: [NSColor whiteColor]
|
||||||
|
@ -239,8 +385,9 @@
|
||||||
|
|
||||||
- (void) windowResignKey: (NSNotification *)notification
|
- (void) windowResignKey: (NSNotification *)notification
|
||||||
{
|
{
|
||||||
|
_isKeyWindow = NO;
|
||||||
RELEASE (titleColor);
|
RELEASE (titleColor);
|
||||||
if ([NSApp isActive] && [_owner isMainWindow])
|
if (_isActiveApplication && _isMainWindow)
|
||||||
{
|
{
|
||||||
titleColor = RETAIN ([NSColor darkGrayColor]);
|
titleColor = RETAIN ([NSColor darkGrayColor]);
|
||||||
[textAttributes setObject: [NSColor whiteColor]
|
[textAttributes setObject: [NSColor whiteColor]
|
||||||
|
@ -255,9 +402,20 @@
|
||||||
[self setNeedsDisplay: YES];
|
[self setNeedsDisplay: YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
- (void) windowBecomeMain: (NSNotification *)notification
|
||||||
* Buttons
|
{
|
||||||
*/
|
_isMainWindow = YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) windowResignMain: (NSNotification *)notification
|
||||||
|
{
|
||||||
|
_isMainWindow = NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// ==== Buttons
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
- (NSButton *) _createButtonWithImage: (NSImage *)image
|
- (NSButton *) _createButtonWithImage: (NSImage *)image
|
||||||
highlightImage: (NSImage *)imageH
|
highlightImage: (NSImage *)imageH
|
||||||
action: (SEL)action
|
action: (SEL)action
|
||||||
|
@ -310,6 +468,11 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSButton *) closeButton
|
||||||
|
{
|
||||||
|
return closeButton;
|
||||||
|
}
|
||||||
|
|
||||||
- (void) removeCloseButton
|
- (void) removeCloseButton
|
||||||
{
|
{
|
||||||
if ([closeButton superview] != nil)
|
if ([closeButton superview] != nil)
|
||||||
|
@ -348,6 +511,11 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSButton *) miniaturizeButton
|
||||||
|
{
|
||||||
|
return miniaturizeButton;
|
||||||
|
}
|
||||||
|
|
||||||
- (void) removeMiniaturizeButton
|
- (void) removeMiniaturizeButton
|
||||||
{
|
{
|
||||||
if ([miniaturizeButton superview] != nil)
|
if ([miniaturizeButton superview] != nil)
|
||||||
|
@ -357,61 +525,5 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Owner setting
|
|
||||||
*/
|
|
||||||
- (void) setOwner: (id)owner
|
|
||||||
{
|
|
||||||
NSNotificationCenter *theCenter = [NSNotificationCenter defaultCenter];
|
|
||||||
|
|
||||||
if ([owner isKindOfClass:[NSWindow class]])
|
|
||||||
{
|
|
||||||
NSDebugLLog(@"GSTitleView", @"owner is NSWindow or NSPanel");
|
|
||||||
_owner = owner;
|
|
||||||
_ownedByMenu = NO;
|
|
||||||
|
|
||||||
[self setFrame:
|
|
||||||
NSMakeRect (0, [_owner frame].size.height - [GSTitleView height],
|
|
||||||
[_owner frame].size.width, [GSTitleView height])];
|
|
||||||
|
|
||||||
[self addCloseButtonWithAction: @selector (performClose:)];
|
|
||||||
|
|
||||||
[self addMiniaturizeButtonWithAction: @selector (performMiniaturize:)];
|
|
||||||
|
|
||||||
// Observers
|
|
||||||
[theCenter addObserver: self
|
|
||||||
selector: @selector(windowBecomeKey:)
|
|
||||||
name: NSWindowDidBecomeKeyNotification
|
|
||||||
object: _owner];
|
|
||||||
[theCenter addObserver: self
|
|
||||||
selector: @selector(windowResignKey:)
|
|
||||||
name: NSWindowDidResignKeyNotification
|
|
||||||
object: _owner];
|
|
||||||
}
|
|
||||||
else if ([owner isKindOfClass:[NSMenu class]])
|
|
||||||
{
|
|
||||||
NSDebugLLog(@"GSTitleView", @"owner is NSMenu");
|
|
||||||
_owner = owner;
|
|
||||||
_ownedByMenu = YES;
|
|
||||||
|
|
||||||
RELEASE (titleColor);
|
|
||||||
titleColor = RETAIN ([NSColor blackColor]);
|
|
||||||
[textAttributes setObject: [NSColor whiteColor]
|
|
||||||
forKey: NSForegroundColorAttributeName];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
NSDebugLLog(@"GSTitleView",
|
|
||||||
@"%@ owner is not NSMenu or NSWindow or NSPanel",
|
|
||||||
[owner className]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
- (id) owner
|
|
||||||
{
|
|
||||||
return _owner;
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue