From 77071bf68c2092d3ee035b4dca9932518c64c9ed Mon Sep 17 00:00:00 2001 From: gcasa Date: Sat, 5 Jan 2008 20:27:10 +0000 Subject: [PATCH] * Headers/AppKit/NSDrawer.h: Added new ivars. * Source/NSDrawer.m: Addition implementation of NSDrawer. Corrected drag problem. Added border. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@25873 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 6 ++ Headers/AppKit/NSDrawer.h | 8 +-- Source/NSDrawer.m | 139 ++++++++++++++++++++++++++++---------- 3 files changed, 115 insertions(+), 38 deletions(-) diff --git a/ChangeLog b/ChangeLog index 24999cb24..ffdfe1746 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-01-05 15:25-EST Gregory John Casamento + + * Headers/AppKit/NSDrawer.h: Added new ivars. + * Source/NSDrawer.m: Addition implementation of NSDrawer. Corrected + drag problem. Added border. + 2008-01-04 Fred Kiefer * Source/NSTextContainer.m: Replace tabs with spaces. diff --git a/Headers/AppKit/NSDrawer.h b/Headers/AppKit/NSDrawer.h index 3a88548a8..e1ade5d90 100644 --- a/Headers/AppKit/NSDrawer.h +++ b/Headers/AppKit/NSDrawer.h @@ -39,10 +39,10 @@ @class NSNotification; enum { - NSDrawerClosedState, - NSDrawerOpeningState, - NSDrawerOpenState, - NSDrawerClosingState + NSDrawerClosedState = 0, + NSDrawerOpeningState = 1, + NSDrawerOpenState = 2, + NSDrawerClosingState = 3 }; @interface NSDrawer : NSResponder diff --git a/Source/NSDrawer.m b/Source/NSDrawer.m index cc8689dc5..017b734f0 100644 --- a/Source/NSDrawer.m +++ b/Source/NSDrawer.m @@ -33,10 +33,12 @@ #include #include #include -#include "AppKit/NSWindow.h" -#include "AppKit/NSBox.h" -#include "AppKit/NSView.h" -#include "AppKit/NSDrawer.h" +#include +#include +#include +#include +#include +#include static NSNotificationCenter *nc = nil; @@ -45,7 +47,8 @@ static NSNotificationCenter *nc = nil; NSWindow *_parentWindow; NSWindow *_pendingParentWindow; NSDrawer *_drawer; - NSBox *_box; + id _container; + NSTimer *_timer; } - (NSRect) frameFromParentWindowFrame; @@ -53,6 +56,8 @@ static NSNotificationCenter *nc = nil; - (void) openOnEdge; - (void) closeOnEdge; - (void) slide; +- (void) startTimer; +- (void) stopTimer; // window/drawer properties - (void) setParentWindow: (NSWindow *)window; @@ -84,6 +89,11 @@ static NSNotificationCenter *nc = nil; defer: (BOOL)flag screen: (NSScreen*)aScreen { + if(NSIsEmptyRect(contentRect)) + { + contentRect = NSMakeRect(0,0,100,100); + } + self = [super initWithContentRect: contentRect styleMask: aStyle backing: bufferingType @@ -91,30 +101,43 @@ static NSNotificationCenter *nc = nil; screen: aScreen]; if (self != nil) { - /* - _box = [[NSBox alloc] init]; - [_box setTitle: @""]; - [_box setTitlePosition: NSNoTitle]; - [_box setBorderType: NSBezelBorder]; - [_box setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable]; - [[super contentView] addSubview: _box]; - */ + NSRect rect = contentRect; + NSRect border = contentRect; + NSBox *borderBox = nil; + + rect.origin.x += 6; + rect.origin.y += 6; + rect.size.width -= 16; + rect.size.height -= 16; + + border.origin.x += 1; + border.origin.y += 1; + border.size.width -= 2; + border.size.height -= 2; + + borderBox = [[NSBox alloc] initWithFrame: border]; + [borderBox setTitle: @""]; + [borderBox setTitlePosition: NSNoTitle]; + [borderBox setBorderType: NSLineBorder]; + [borderBox setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable]; + [borderBox setContentViewMargins: NSMakeSize(0,0)]; + [[super contentView] addSubview: borderBox]; + + _container = [[NSBox alloc] initWithFrame: rect]; + [_container setTitle: @""]; + [_container setTitlePosition: NSNoTitle]; + [_container setBorderType: NSBezelBorder]; + [_container setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable]; + [borderBox addSubview: _container]; } return self; } -/* -- (void) setContentView: (NSView *)view +- (id) container { - [_box setContentView: view]; + return _container; } -- (NSView *) contentView -{ - return [_box contentView]; -} -*/ - - (NSRect) frameFromParentWindowFrame { NSRect newFrame = [_parentWindow frame]; @@ -177,16 +200,51 @@ static NSNotificationCenter *nc = nil; [self setFrame: tempFrame display: YES]; } +- (void) startTimer +{ + NSTimeInterval time = 3.0; + _timer = [NSTimer scheduledTimerWithTimeInterval: time + target: self + selector: @selector(_timedWindowReset) + userInfo: nil + repeats: YES]; +} + +- (void) stopTimer +{ + [_timer invalidate]; +} + +- (void) orderFrontRegardless +{ + [self orderFront: self]; +} + +- (void) orderOut: (id)sender +{ + [super orderOut: sender]; +} + +/* +- (void) orderWindow: (NSWindowOrderingMode)place relativeTo: (int)windowNum +{ + NSLog(@"Ordering window...."); + [super orderWindow: place relativeTo: windowNum]; +} +*/ + - (void) openOnEdge { [self orderFront: self]; [self slide]; + // [self startTimer]; } - (void) closeOnEdge { - NSRect frame = [self frameFromParentWindowFrame]; // : [_parentWindow frame]]; - // slide the drawer closed.... + NSRect frame = [self frameFromParentWindowFrame]; + + // [self stopTimer]; [self slide]; [self setFrame: frame display: YES]; [self orderOut: self]; @@ -196,7 +254,7 @@ static NSNotificationCenter *nc = nil; { [self setParentWindow: _pendingParentWindow]; ASSIGN(_pendingParentWindow, nil); - } + } } - (void) slide @@ -255,21 +313,34 @@ static NSNotificationCenter *nc = nil; } } +- (void) _resetWindowPosition +{ + NSRect frame = [self frameFromParentWindowFrame]; + [self setFrame: frame display: YES]; +} + +- (void) _timedWindowReset +{ + NSRect frame = [_parentWindow frame]; + [self _resetWindowPosition]; + [_parentWindow setFrame: frame display: YES]; +} + - (void) handleWindowClose: (NSNotification *)notification { + [self stopTimer]; [self close]; } - (void) handleWindowMiniaturize: (NSNotification *)notification { + [self stopTimer]; [self close]; } - (void) handleWindowMove: (NSNotification *)notification { - NSRect frame = [self frameFromParentWindowFrame]; // : [obj frame]]; - NSLog(@"%@",NSStringFromRect(frame)); - [self setFrame: frame display: NO]; + [self _resetWindowPosition]; } - (void) setParentWindow: (NSWindow *)window @@ -281,8 +352,7 @@ static NSNotificationCenter *nc = nil; if (_parentWindow != nil) { - NSRect frame = [self frameFromParentWindowFrame]; - [self setFrame: frame display: YES]; + [self _resetWindowPosition]; // add observers.... [nc addObserver: self @@ -297,7 +367,7 @@ static NSNotificationCenter *nc = nil; [nc addObserver: self selector: @selector(handleWindowMove:) - name: NSWindowDidMoveNotification + name: NSWindowWillMoveNotification object: _parentWindow]; [nc addObserver: self @@ -336,6 +406,7 @@ static NSNotificationCenter *nc = nil; - (void) dealloc { + [self stopTimer]; RELEASE(_parentWindow); TEST_RELEASE(_pendingParentWindow); [super dealloc]; @@ -356,7 +427,7 @@ static NSNotificationCenter *nc = nil; // Creation - (id) init { - return [self initWithContentSize: NSZeroSize + return [self initWithContentSize: NSMakeSize(100,100) preferredEdge: NSMinXEdge]; } @@ -550,7 +621,7 @@ static NSNotificationCenter *nc = nil; // Managing Views - (NSView *) contentView { - return [_drawerWindow contentView]; + return [[_drawerWindow container] contentView]; } - (NSWindow *) parentWindow @@ -560,7 +631,7 @@ static NSNotificationCenter *nc = nil; - (void) setContentView: (NSView *)aView { - [_drawerWindow setContentView: aView]; + [[_drawerWindow container] setContentView: aView]; } - (void) setParentWindow: (NSWindow *)parent