Index: Headers/Additions/GNUstepGUI/GSDisplayServer.h =================================================================== RCS file: /cvsroot/gnustep/gnustep/core/gui/Headers/Additions/GNUstepGUI/GSDisplayServer.h,v retrieving revision 1.1 diff -u -r1.1 GSDisplayServer.h --- Headers/Additions/GNUstepGUI/GSDisplayServer.h 31 Jul 2003 23:52:08 -0000 1.1 +++ Headers/Additions/GNUstepGUI/GSDisplayServer.h 22 Jan 2004 11:51:10 -0000 @@ -72,6 +72,8 @@ - glContextClass; - glPixelFormatClass; +- (BOOL) handlesWindowDecorations; + /* Drag and drop support. */ + (BOOL) addDragTypes: (NSArray*)types toWindow: (NSWindow *)win; + (BOOL) removeDragTypes: (NSArray*)types fromWindow: (NSWindow *)win; @@ -107,7 +109,7 @@ - (void) termwindow: (int) win; - (void) stylewindow: (unsigned int) style : (int) win; - (void) windowbacking: (NSBackingStoreType)type : (int) win; -- (void) titlewindow: (NSString *) window_title : (int) win; +- (void) titlewindow: (NSString *) window_title : (int) win; /* Only if handlesWindowDecorations. */ - (void) miniwindow: (int) win; - (BOOL) appOwnsMiniwindow; - (void) windowdevice: (int) win; @@ -125,8 +127,8 @@ - (void) flushwindowrect: (NSRect)rect : (int) win; - (void) styleoffsets: (float*) l : (float*) r : (float*) t : (float*) b : (unsigned int) style; -- (void) docedited: (int) edited : (int) win; -- (void) setinputstate: (int)state : (int)win; +- (void) docedited: (int) edited : (int) win; /* Only if handlesWindowDecorations. */ +- (void) setinputstate: (int)state : (int)win; /* Only if handlesWindowDecorations. */ - (void) setinputfocus: (int) win; - (NSPoint) mouselocation; Index: Headers/AppKit/NSWindow.h =================================================================== RCS file: /cvsroot/gnustep/gnustep/core/gui/Headers/AppKit/NSWindow.h,v retrieving revision 1.3 diff -u -r1.3 NSWindow.h --- Headers/AppKit/NSWindow.h 11 Nov 2003 19:40:18 -0000 1.3 +++ Headers/AppKit/NSWindow.h 22 Jan 2004 11:51:10 -0000 @@ -60,6 +60,8 @@ @class NSWindowController; @class NSCachedImageRep; +@class GSWindowDecorationView; + /* * Window levels are taken from MacOS-X * NSDesktopWindowLevel is copied from Window maker and is intended to be @@ -101,12 +103,33 @@ @interface NSWindow : NSResponder { - NSRect _frame; + /* + _screenFrame is the frame of the _entire_ window on the screen, including + all decorations and borders (regardless of where they come from). + (Depending on the backend, this frame might not be completely accurate.) + + _windowFrame is the frame of the backend window for this window, and is + thus the base of the coordinate system for the window. + + _contentRect is the frame of the content view. + + + Wrt. size, _screenFrame >= _windowFrame >= _contentRect. When -gui doesn't + manage the window decorations, _windowFrame == _contentRect. When -gui does + manage the window decorations, _windowFrame will include the decorations, + and unless the backend/windowing system adds extra borders, + _screenFrame == _windowFrame. + */ +// NSRect _screenFrame; + NSRect _windowFrame; +// NSRect _contentRect; + + NSSize _minimumSize; NSSize _maximumSize; NSSize _increments; NSString *_autosaveName; - id _wv; + GSWindowDecorationView *_wv; id _contentView; id _firstResponder; id _futureFirstResponder; @@ -186,14 +209,17 @@ /* * Computing frame and content rectangles */ +/* window frame */ + (NSRect) contentRectForFrameRect: (NSRect)aRect styleMask: (unsigned int)aStyle; +/* window frame */ + (NSRect) frameRectForContentRect: (NSRect)aRect styleMask: (unsigned int)aStyle; -+ (NSRect) minFrameWidthWithTitle: (NSString *)aTitle - styleMask: (unsigned int)aStyle; +/* window frame */ ++ (float) minFrameWidthWithTitle: (NSString *)aTitle + styleMask: (unsigned int)aStyle; /* @@ -219,17 +245,17 @@ /* * Moving and resizing the window */ -- (NSRect) frame; +- (NSRect) frame; /* window frame */ - (void) setFrame: (NSRect)frameRect display: (BOOL)flag; -- (void) setFrameOrigin: (NSPoint)aPoint; -- (void) setFrameTopLeftPoint: (NSPoint)aPoint; +- (void) setFrameOrigin: (NSPoint)aPoint; /* window frame */ +- (void) setFrameTopLeftPoint: (NSPoint)aPoint; /* window frame */ - (void) setContentSize: (NSSize)aSize; -- (NSPoint) cascadeTopLeftFromPoint: (NSPoint)topLeftPoint; +- (NSPoint) cascadeTopLeftFromPoint: (NSPoint)topLeftPoint; /* window frame */ - (void) center; - (int) resizeFlags; #ifndef STRICT_OPENSTEP -- (void) setFrame: (NSRect)frameRect +- (void) setFrame: (NSRect)frameRect /* window frame */ display: (BOOL)displayFlag animate: (BOOL)animationFlag; - (NSTimeInterval) animationResizeTime: (NSRect)newFrame; @@ -242,31 +268,31 @@ /* * Constraining size */ -- (NSSize) minSize; -- (NSSize) maxSize; -- (void) setMinSize: (NSSize)aSize; -- (void) setMaxSize: (NSSize)aSize; -- (NSRect) constrainFrameRect: (NSRect)frameRect +- (NSSize) minSize; /* content rect */ +- (NSSize) maxSize; /* content rect */ +- (void) setMinSize: (NSSize)aSize; /* content rect */ +- (void) setMaxSize: (NSSize)aSize; /* content rect */ +- (NSRect) constrainFrameRect: (NSRect)frameRect /* screen frame */ toScreen: (NSScreen*)screen; #ifndef STRICT_OPENSTEP -- (NSSize) aspectRatio; -- (void) setAspectRatio: (NSSize)ratio; -- (NSSize) resizeIncrements; -- (void) setResizeIncrements: (NSSize)aSize; +- (NSSize) aspectRatio; /* content rect */ +- (void) setAspectRatio: (NSSize)ratio; /* content rect */ +- (NSSize) resizeIncrements; /* content rect */ +- (void) setResizeIncrements: (NSSize)aSize; /* content rect */ #endif /* * Saving and restoring the frame */ -+ (void) removeFrameUsingName: (NSString*)name; -- (NSString*) frameAutosaveName; -- (void) saveFrameUsingName: (NSString*)name; -- (BOOL) setFrameAutosaveName: (NSString*)name; -- (void) setFrameFromString: (NSString*)string; -- (BOOL) setFrameUsingName: (NSString*)name; -- (NSString*) stringWithSavedFrame; ++ (void) removeFrameUsingName: (NSString*)name; /* window frame */ +- (NSString*) frameAutosaveName; /* window frame */ +- (void) saveFrameUsingName: (NSString*)name; /* window frame */ +- (BOOL) setFrameAutosaveName: (NSString*)name; /* window frame */ +- (void) setFrameFromString: (NSString*)string; /* window frame */ +- (BOOL) setFrameUsingName: (NSString*)name; /* window frame */ +- (NSString*) stringWithSavedFrame; /* window frame */ #ifndef STRICT_OPENSTEP -- (BOOL) setFrameUsingName: (NSString *)name +- (BOOL) setFrameUsingName: (NSString *)name /* window frame */ force: (BOOL)force; #endif Index: Source/GSDisplayServer.m =================================================================== RCS file: /cvsroot/gnustep/gnustep/core/gui/Source/GSDisplayServer.m,v retrieving revision 1.21 diff -u -r1.21 GSDisplayServer.m --- Source/GSDisplayServer.m 10 Jan 2004 19:40:43 -0000 1.21 +++ Source/GSDisplayServer.m 22 Jan 2004 11:51:10 -0000 @@ -277,6 +277,12 @@ } +- (BOOL) handlesWindowDecorations +{ + return YES; +} + + /* Drag and drop support. */ /** Convienience method that calls -addDragTypes:toWindow: using the server that controls win. Index: Source/NSView.m =================================================================== RCS file: /cvsroot/gnustep/gnustep/core/gui/Source/NSView.m,v retrieving revision 1.217 diff -u -r1.217 NSView.m --- Source/NSView.m 30 Dec 2003 12:42:37 -0000 1.217 +++ Source/NSView.m 22 Jan 2004 11:51:14 -0000 @@ -2528,8 +2528,13 @@ unsigned count; NSView *v = nil, *w; - /* If not within our frame then it can't be a hit */ - if (![_super_view mouse: aPoint inRect: _frame]) + /* + If not within our frame then it can't be a hit. + + As a special case, always assume it's a hit if our _super_view is nil. + This should only happen for the top-level view in a window. + */ + if (_super_view && ![_super_view mouse: aPoint inRect: _frame]) return nil; p = [self convertPoint: aPoint fromView: _super_view]; @@ -2539,7 +2544,7 @@ count = [_sub_views count]; if (count > 0) { - NSView* array[count]; + NSView *array[count]; [_sub_views getObjects: array]; Index: Source/NSWindow.m =================================================================== RCS file: /cvsroot/gnustep/gnustep/core/gui/Source/NSWindow.m,v retrieving revision 1.303 diff -u -r1.303 NSWindow.m --- Source/NSWindow.m 15 Jan 2004 10:04:04 -0000 1.303 +++ Source/NSWindow.m 22 Jan 2004 11:51:15 -0000 @@ -51,6 +51,7 @@ #include "AppKit/NSWindow.h" #include "AppKit/NSWindowController.h" #include "AppKit/NSApplication.h" +#include "AppKit/NSButton.h" #include "AppKit/NSButtonCell.h" #include "AppKit/NSMenu.h" #include "AppKit/NSImage.h" @@ -72,6 +73,751 @@ #include "GNUstepGUI/GSDisplayServer.h" #include "GNUstepGUI/GSToolbarView.h" + +@protocol GSWindowDecorator +- (id) newWindowDecorationViewWithFrame: (NSRect)frame + window: (NSWindow *)window; + +- (NSRect) contentRectForFrameRect: (NSRect)aRect + styleMask: (unsigned int)aStyle; +- (NSRect) frameRectForContentRect: (NSRect)aRect + styleMask: (unsigned int)aStyle; +- (float) minFrameWidthWithTitle: (NSString *)aTitle + styleMask: (unsigned int)aStyle; +@end + + +static id windowDecorator; + +/* +Abstract superclass for the top-level view in each window. This view is +responsible for managing window decorations. Concrete subclasses may do +this, either directly, or indirectly (by using the backend). +*/ +@interface GSWindowDecorationView : NSView +{ + NSWindow *window; /* not retained */ + + NSRect contentRect; + int inputState; +} ++(id) windowDecorator; + +- initWithFrame: (NSRect)frame + window: (NSWindow *)w; + +-(void) setTitle: (NSString *)title; +-(void) setInputState: (int)state; +-(void) setDocumentEdited: (BOOL)flag; +@end + + +/* +Manage window decorations by using the backend functions. This only works +on backends that can handle window decorations. +*/ +@interface GSBackendWindowDecorationView : GSWindowDecorationView + +#if 0 +/* setTitle: */ +-(void) setTitle: (NSString *)title; + if (_windowNum > 0) + [GSServerForWindow(self) titlewindow: aString : _windowNum]; + +/* setInputState: */ + [GSServerForWindow(self) setinputstate: GSTitleBarKey : _windowNum]; + +/* setDocumentEdited: */ + if (_windowNum) + [GSServerForWindow(self) docedited: flag : _windowNum]; +#endif + +@end + + +/* +Standard OPENSTEP-ish window decorations. +*/ +@interface GSStandardWindowDecorationView : GSWindowDecorationView +{ + NSString *title; + + BOOL hasTitleBar, hasResizeBar, hasCloseButton, hasMiniaturizeButton; + BOOL isTitled; + NSRect titleBarRect; + NSRect resizeBarRect; + NSRect closeButtonRect; + NSRect miniaturizeButtonRect; + + NSButton *closeButton, *miniaturizeButton; +} + +@end + + +@implementation GSWindowDecorationView + ++(id) windowDecorator +{ + if ([GSCurrentServer() handlesWindowDecorations]) + return [GSBackendWindowDecorationView self]; + else + return [GSStandardWindowDecorationView self]; +} + + ++(id) newWindowDecorationViewWithFrame: (NSRect)frame + window: (NSWindow *)aWindow +{ + return [[self alloc] initWithFrame: frame + window: aWindow]; +} + + ++(void) offsets: (float *)l : (float *)r : (float *)t : (float *)b + forStyleMask: (unsigned int)style +{ + [self subclassResponsibility: _cmd]; +} + ++ (NSRect) contentRectForFrameRect: (NSRect)aRect + styleMask: (unsigned int)aStyle +{ + float t, b, l, r; + + [self offsets: &l : &r : &t : &b + forStyleMask: aStyle]; + aRect.size.width -= l + r; + aRect.size.height -= t + b; + aRect.origin.x += l; + aRect.origin.y += b; + return aRect; +} + ++ (NSRect) frameRectForContentRect: (NSRect)aRect + styleMask: (unsigned int)aStyle +{ + float t, b, l, r; + + [self offsets: &l : &r : &t : &b + forStyleMask: aStyle]; + aRect.size.width += l + r; + aRect.size.height += t + b; + aRect.origin.x -= l; + aRect.origin.y -= b; + return aRect; +} + ++ (float) minFrameWidthWithTitle: (NSString *)aTitle + styleMask: (unsigned int)aStyle +{ + [self subclassResponsibility: _cmd]; + return 0.0; +} + + +- initWithFrame: (NSRect)frame +{ + NSAssert(NO, @"Tried to create GSWindowDecorationView without a window!"); + return nil; +} + +- initWithFrame: (NSRect)frame + window: (NSWindow *)w +{ + self = [super initWithFrame: frame]; + if (self) + window = w; + + contentRect = frame; + contentRect.origin = NSMakePoint(0.0, 0.0); + contentRect = [isa contentRectForFrameRect: contentRect + styleMask: [window styleMask]]; + + return self; +} + +-(void) setTitle: (NSString *)title +{ + [self subclassResponsibility: _cmd]; +} +-(void) setInputState: (int)state +{ + inputState = state; +} +-(void) setDocumentEdited: (BOOL)flag +{ + [self subclassResponsibility: _cmd]; +} + +- (BOOL) isOpaque +{ + return YES; +} + +- (void) drawRect: (NSRect)rect +{ + NSColor *c = [_window backgroundColor]; + + if (NSIntersectsRect(rect, contentRect)) + { + [c set]; + NSRectFill(contentRect); + } +} + +/* + * Special setFrame: implementation - a minimal autoresize mechanism + */ +- (void) setFrame: (NSRect)frameRect +{ + NSSize oldSize = _frame.size; + NSView *cv = [_window contentView]; + + _autoresizes_subviews = NO; + [super setFrame: frameRect]; + + contentRect = frameRect; + contentRect.origin = NSMakePoint(0.0, 0.0); + contentRect = [isa contentRectForFrameRect: contentRect + styleMask: [window styleMask]]; + + // Safety Check. + [cv setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable]; + [cv resizeWithOldSuperviewSize: oldSize]; +} + + +- (void) setContentView: (NSView *)contentView +{ + float t, b, l, r; + NSSize oldSize; + + [isa offsets: &l : &r : &t : &b + forStyleMask: [window styleMask]]; + + [contentView setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable]; + [self addSubview: contentView]; + + oldSize = [contentView frame].size; + oldSize.width += l + r; + oldSize.height += t + b; + [contentView resizeWithOldSuperviewSize: oldSize]; + [contentView setFrameOrigin: NSMakePoint(l, b)]; +} + + +- initWithCoder: (NSCoder*)aCoder +{ + NSAssert(NO, @"The top-level window view should never be encoded."); + return nil; +} +-(void) encodeWithCoder: (NSCoder*)aCoder +{ + NSAssert(NO, @"The top-level window view should never be encoded."); +} + +@end + + +@implementation GSBackendWindowDecorationView +@end + + +@implementation GSStandardWindowDecorationView + +/* These include the black border. */ +#define TITLE_HEIGHT 23.0 +#define RESIZE_HEIGHT 9.0 + ++(void) offsets: (float *)l : (float *)r : (float *)t : (float *)b + forStyleMask: (unsigned int)style +{ + if (style + & (NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)) + *l = *r = *t = *b = 1.0; + else + *l = *r = *t = *b = 0.0; + + if (style + & (NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask)) + { + *t = TITLE_HEIGHT; + } + if (style & NSResizableWindowMask) + { + *b = RESIZE_HEIGHT; + } +} + ++ (float) minFrameWidthWithTitle: (NSString *)aTitle + styleMask: (unsigned int)aStyle +{ + float l, r, t, b, width; + [self offsets: &l : &r : &t : &b + forStyleMask: aStyle]; + + width = l + r; + + if (aStyle & NSTitledWindowMask) + width += [aTitle sizeWithAttributes: nil].width; + + return width; +} + + +static NSDictionary *titleTextAttributes[3]; +static NSColor *titleColor[3]; + +-(void) updateRects +{ + if (hasTitleBar) + titleBarRect = NSMakeRect(0.0, _frame.size.height - TITLE_HEIGHT, _frame.size.width, TITLE_HEIGHT); + if (hasResizeBar) + resizeBarRect = NSMakeRect(0.0, 0.0, _frame.size.width, RESIZE_HEIGHT); + + if (hasCloseButton) + { + closeButtonRect = NSMakeRect( + _frame.size.width - 15 - 4, _frame.size.height - 15 - 4, 15, 15); + [closeButton setFrame: closeButtonRect]; + } + + if (hasMiniaturizeButton) + { + miniaturizeButtonRect = NSMakeRect(4, _frame.size.height - 15 - 4, 15, 15); + [miniaturizeButton setFrame: miniaturizeButtonRect]; + } +} + +- initWithFrame: (NSRect)frame + window: (NSWindow *)w +{ + if (!titleTextAttributes[0]) + { + titleTextAttributes[0] = [[NSMutableDictionary alloc] initWithObjectsAndKeys: + [NSFont titleBarFontOfSize: 0], NSFontAttributeName, + [NSColor windowFrameTextColor], NSForegroundColorAttributeName, + nil]; + titleTextAttributes[1] = [[NSMutableDictionary alloc] initWithObjectsAndKeys: + [NSFont titleBarFontOfSize: 0], NSFontAttributeName, + [NSColor blackColor], NSForegroundColorAttributeName, /* TODO: need a named color for this */ + nil]; + titleTextAttributes[2] = [[NSMutableDictionary alloc] initWithObjectsAndKeys: + [NSFont titleBarFontOfSize: 0], NSFontAttributeName, + [NSColor windowFrameTextColor], NSForegroundColorAttributeName, + nil]; + + titleColor[0] = RETAIN([NSColor windowFrameColor]); + titleColor[1] = RETAIN([NSColor lightGrayColor]); + titleColor[2] = RETAIN([NSColor darkGrayColor]); + } + + self = [super initWithFrame: frame + window: w]; + if (!self) return nil; + + if ([w styleMask] + & (NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask)) + { + hasTitleBar = YES; + } + if ([w styleMask] & NSTitledWindowMask) + isTitled = YES; + if ([w styleMask] & NSClosableWindowMask) + { + hasCloseButton = YES; + + closeButton = [[NSButton alloc] init]; + [closeButton setRefusesFirstResponder: YES]; + [closeButton setButtonType: NSMomentaryChangeButton]; + [closeButton setImagePosition: NSImageOnly]; + [closeButton setBordered: YES]; + [closeButton setImage: [NSImage imageNamed: @"common_Close"]]; + [closeButton setAlternateImage: [NSImage imageNamed: @"common_CloseH"]]; + [closeButton setTarget: window]; + /* TODO: -performClose: should (but doesn't currently) highlight the button, which is wrong here */ + [closeButton setAction: @selector(performClose:)]; + [self addSubview: closeButton]; + RELEASE(closeButton); + } + if ([w styleMask] & NSMiniaturizableWindowMask) + { + hasMiniaturizeButton = YES; + + miniaturizeButton = [[NSButton alloc] init]; + [miniaturizeButton setRefusesFirstResponder: YES]; + [miniaturizeButton setButtonType: NSMomentaryChangeButton]; + [miniaturizeButton setImagePosition: NSImageOnly]; + [miniaturizeButton setBordered: YES]; + [miniaturizeButton setImage: [NSImage imageNamed: @"common_Miniaturize"]]; + [miniaturizeButton setAlternateImage: [NSImage imageNamed: @"common_MiniaturizeH"]]; + [miniaturizeButton setTarget: window]; + /* TODO: -performMiniaturize: should (but doesn't currently) highlight the button, which is wrong here */ + [miniaturizeButton setAction: @selector(performMiniaturize:)]; + [self addSubview: miniaturizeButton]; + RELEASE(miniaturizeButton); + } + if ([w styleMask] & NSResizableWindowMask) + hasResizeBar = YES; + + [self updateRects]; + + return self; +} + + +- (void) setFrame: (NSRect)frameRect +{ + [super setFrame: frameRect]; + + [self updateRects]; +} + + +-(void) drawTitleBar +{ + /* from GSTitleView.m */ + NSRect workRect = titleBarRect; + NSSize titleSize; + NSRectEdge top_left[] = {NSMinXEdge, NSMaxYEdge}; + NSRectEdge bottom_right[] = {NSMaxXEdge, NSMinYEdge}; + float blacks[] = {NSBlack, NSBlack}; + float grays[] = {NSLightGray, NSLightGray}; + + // Draw the dark gray upper left lines for menu and black for others. + // Rectangle 1 + workRect = NSDrawTiledRects(workRect, workRect, top_left, blacks, 2); + + // Rectangle 2 + // Draw the title box's button. + NSDrawButton(workRect, workRect); + + // 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 (inputState == GSTitleBarKey || inputState == GSTitleBarMain) + { + NSDrawTiledRects(workRect, workRect, top_left, grays, 2); + } + + // Rectangle 3 + // Paint background + workRect.origin.x += 1; + workRect.origin.y += 1; + workRect.size.height -= 2; + workRect.size.width -= 2; + + [titleColor[inputState] set]; + NSRectFill(workRect); + + if (inputState == GSTitleBarMain) + { + 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. */ + if (isTitled) + { + titleSize = [title sizeWithAttributes: titleTextAttributes[inputState]]; + workRect.origin.x += NSMidX(workRect) - titleSize.width / 2; + workRect.origin.y = NSMidY(workRect) - titleSize.height / 2; + workRect.size.height = titleSize.height; + [title drawInRect: workRect + withAttributes: titleTextAttributes[inputState]]; + } +} + +-(void) drawResizeBar +{ + [[NSColor lightGrayColor] set]; + PSrectfill(1.0, 1.0, resizeBarRect.size.width - 2.0, RESIZE_HEIGHT - 3.0); + + PSsetlinewidth(1.0); + + [[NSColor blackColor] set]; + PSmoveto(0.0, 0.5); + PSlineto(resizeBarRect.size.width, 0.5); + PSstroke(); + + [[NSColor darkGrayColor] set]; + PSmoveto(1.0, RESIZE_HEIGHT - 0.5); + PSlineto(resizeBarRect.size.width - 1.0, RESIZE_HEIGHT - 0.5); + PSstroke(); + + [[NSColor whiteColor] set]; + PSmoveto(1.0, RESIZE_HEIGHT - 1.5); + PSlineto(resizeBarRect.size.width - 1.0, RESIZE_HEIGHT - 1.5); + PSstroke(); + + + /* Only draw the notches if there's enough space. */ + if (resizeBarRect.size.width < 30 * 2) + return; + + [[NSColor darkGrayColor] set]; + PSmoveto(27.5, 1.0); + PSlineto(27.5, RESIZE_HEIGHT - 2.0); + PSmoveto(resizeBarRect.size.width - 28.5, 1.0); + PSlineto(resizeBarRect.size.width - 28.5, RESIZE_HEIGHT - 2.0); + PSstroke(); + + [[NSColor whiteColor] set]; + PSmoveto(28.5, 1.0); + PSlineto(28.5, RESIZE_HEIGHT - 2.0); + PSmoveto(resizeBarRect.size.width - 27.5, 1.0); + PSlineto(resizeBarRect.size.width - 27.5, RESIZE_HEIGHT - 2.0); + PSstroke(); +} + +-(void) drawRect: (NSRect)rect +{ + if (hasTitleBar && NSIntersectsRect(rect, titleBarRect)) + { + [self drawTitleBar]; + } + + if (hasResizeBar && NSIntersectsRect(rect, resizeBarRect)) + { + [self drawResizeBar]; + } + + if (hasResizeBar || hasTitleBar) + { + PSsetlinewidth(1.0); + [[NSColor blackColor] set]; + if (NSMinX(rect) < 1.0) + { + PSmoveto(0.5, 0.0); + PSlineto(0.5, _frame.size.height); + PSstroke(); + } + if (NSMaxX(rect) > _frame.size.width - 1.0) + { + PSmoveto(_frame.size.width - 0.5, 0.0); + PSlineto(_frame.size.width - 0.5, _frame.size.height); + PSstroke(); + } + } + + [super drawRect: rect]; +} + + +-(void) setTitle: (NSString *)newTitle +{ +// printf("setting title to |%@| for view %@ in window %@\n",newTitle,self,window); + ASSIGNCOPY(title, newTitle); + if (isTitled) + [self setNeedsDisplayInRect: titleBarRect]; +} + +-(void) setInputState: (int)state +{ +// printf("setting input state to %i for view %@ in window %@\n",state,self,window); + NSAssert(state >= 0 && state <= 2, @"Invalid state!"); + [super setInputState: state]; + if (hasTitleBar) + [self setNeedsDisplayInRect: titleBarRect]; +} + +-(void) setDocumentEdited: (BOOL)flag +{ + if (flag) + { + [closeButton setImage: [NSImage imageNamed: @"common_CloseBroken"]]; + [closeButton setAlternateImage: [NSImage imageNamed: @"common_CloseBrokenH"]]; + } + else + { + [closeButton setImage: [NSImage imageNamed: @"common_Close"]]; + [closeButton setAlternateImage: [NSImage imageNamed: @"common_CloseH"]]; + } +} + + +-(void) dealloc +{ + DESTROY(title); + [super dealloc]; +} + + +-(NSPoint) mouseLocationOnScreenOutsideOfEventStream +{ + int screen = [[window screen] screenNumber]; + return [GSServerForWindow(window) mouseLocationOnScreen: screen + window: NULL]; +} + +-(void) moveWindowStartingWithEvent: (NSEvent *)event +{ + unsigned int mask = NSLeftMouseDraggedMask | NSLeftMouseUpMask; + NSEvent *currentEvent = event; + NSDate *distantPast = [NSDate distantPast]; + NSPoint delta, point; + + delta = [event locationInWindow]; + + [window _captureMouse: nil]; + do + { + while (currentEvent && [currentEvent type] != NSLeftMouseUp) + { + currentEvent = [_window nextEventMatchingMask: mask + untilDate: distantPast + inMode: NSEventTrackingRunLoopMode + dequeue: YES]; + } + + point = [self mouseLocationOnScreenOutsideOfEventStream]; + [window setFrameOrigin: NSMakePoint(point.x - delta.x, point.y - delta.y)]; + + if (currentEvent && [currentEvent type] == NSLeftMouseUp) + break; + + + currentEvent = [_window nextEventMatchingMask: mask + untilDate: nil + inMode: NSEventTrackingRunLoopMode + dequeue: YES]; + } while ([currentEvent type] != NSLeftMouseUp); + [window _releaseMouse: nil]; +} + + +static NSRect calc_new_frame(NSRect frame, NSPoint point, NSPoint firstPoint, + int mode, NSSize minSize, NSSize maxSize) +{ + NSRect newFrame = frame; + newFrame.origin.y = point.y - firstPoint.y; + newFrame.size.height = NSMaxY(frame) - newFrame.origin.y; + if (newFrame.size.height < minSize.height) + { + newFrame.size.height = minSize.height; + newFrame.origin.y = NSMaxY(frame) - newFrame.size.height; + } + + if (mode == 0) + { + newFrame.origin.x = point.x - firstPoint.x; + newFrame.size.width = NSMaxX(frame) - newFrame.origin.x; + + if (newFrame.size.width < minSize.width) + { + newFrame.size.width = minSize.width; + newFrame.origin.x = NSMaxX(frame) - newFrame.size.width; + } + } + else if (mode == 1) + { + newFrame.size.width = point.x - frame.origin.x + frame.size.width - firstPoint.x; + + if (newFrame.size.width < minSize.width) + { + newFrame.size.width = minSize.width; + newFrame.origin.x = frame.origin.x; + } + } + return newFrame; +} + +-(void) resizeWindowStartingWithEvent: (NSEvent *)event +{ + unsigned int mask = NSLeftMouseDraggedMask | NSLeftMouseUpMask; + NSEvent *currentEvent = event; + NSDate *distantPast = [NSDate distantPast]; + NSPoint firstPoint, point; + NSRect newFrame, frame; + NSSize minSize, maxSize; + + /* + 0 drag lower left corner + 1 drag lower right corner + 2 drag lower edge + */ + int mode; + + + firstPoint = [event locationInWindow]; + if (resizeBarRect.size.width < 30 * 2 && firstPoint.x < resizeBarRect.size.width / 2) + mode = 0; + else if (firstPoint.x > resizeBarRect.size.width - 29) + mode = 1; + else if (firstPoint.x < 29) + mode = 0; + else + mode = 2; + + frame = [window frame]; + minSize = [window minSize]; + maxSize = [window maxSize]; + + [window _captureMouse: nil]; + [self startFramePreview: frame]; + do + { + while (currentEvent && [currentEvent type] != NSLeftMouseUp) + { + currentEvent = [_window nextEventMatchingMask: mask + untilDate: distantPast + inMode: NSEventTrackingRunLoopMode + dequeue: YES]; + } + + point = [self mouseLocationOnScreenOutsideOfEventStream]; + newFrame = calc_new_frame(frame, point, firstPoint, mode, minSize, maxSize); + [self updateFramePreview: newFrame]; + + if (currentEvent && [currentEvent type] == NSLeftMouseUp) + break; + + currentEvent = [_window nextEventMatchingMask: mask + untilDate: nil + inMode: NSEventTrackingRunLoopMode + dequeue: YES]; + } while ([currentEvent type] != NSLeftMouseUp); + [self stopFramePreview]; + [window _releaseMouse: nil]; + + [window setFrame: newFrame display: YES]; +} + +-(BOOL) acceptsFirstMouse: (NSEvent*)theEvent +{ + return YES; +} + +-(void) mouseDown: (NSEvent *)event +{ + NSPoint p = [self convertPoint: [event locationInWindow] fromView: nil]; + + if (NSPointInRect(p, contentRect)) + return; + + if (NSPointInRect(p, titleBarRect)) + { + [self moveWindowStartingWithEvent: event]; + return; + } + + if (NSPointInRect(p, resizeBarRect)) + { + [self resizeWindowStartingWithEvent: event]; + return; + } +} + +@end + + + BOOL GSViewAcceptsDrag(NSView *v, id dragInfo); static NSArray *modes = nil; @@ -100,7 +846,7 @@ /* This method handles all normal displaying. It is set to be run on each runloop iteration for each window that's on-screen. The performer is -added then the window is ordered in and re-added each time it is run. +added when the window is ordered in and re-added each time it is run. If the window is ordered out, the performer is cancelled. The reason why this performer is always added, as opposed to adding it @@ -391,53 +1137,6 @@ -@interface GSWindowView : NSView -{ -} -@end - -@implementation GSWindowView - -- (BOOL) isOpaque -{ - return YES; -} - -- (void) drawRect: (NSRect)rect -{ - NSColor *c = [[self window] backgroundColor]; - - NSDebugLLog(@"NSView", @"-drawRect: %@ for %@ in window %p (%@)", - NSStringFromRect(rect), self, _window, - NSStringFromRect([_window frame])); - [c set]; - NSRectFill(rect); -} - -/* - * Special setFrame: implementation - a minimal autoresize mechanism - */ -- (void) setFrame: (NSRect)frameRect -{ - NSSize oldSize = _frame.size; - NSView *cv = [_window contentView]; - - _autoresizes_subviews = NO; - [super setFrame: frameRect]; - // Safety Check. - [cv setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)]; - [cv resizeWithOldSuperviewSize: oldSize]; -} - -- (Class) classForCoder: (NSCoder*)aCoder -{ - if ([self class] == [GSWindowView class]) - return [super class]; - return [self class]; -} - -@end - /***************************************************************************** * * NSWindow @@ -539,32 +1238,33 @@ + (NSRect) contentRectForFrameRect: (NSRect)aRect styleMask: (unsigned int)aStyle { - float t, b, l, r; + if (!windowDecorator) + windowDecorator = [GSWindowDecorationView windowDecorator]; - [GSCurrentServer() styleoffsets: &l : &r : &t : &b : aStyle]; - aRect.size.width -= (l + r); - aRect.size.height -= (t + b); - aRect.origin.x += l; - aRect.origin.y += b; - return aRect; + return [windowDecorator contentRectForFrameRect: aRect + styleMask: aStyle]; } + (NSRect) frameRectForContentRect: (NSRect)aRect styleMask: (unsigned int)aStyle { - float t, b, l, r; + if (!windowDecorator) + windowDecorator = [GSWindowDecorationView windowDecorator]; - [GSCurrentServer() styleoffsets: &l : &r : &t : &b : aStyle]; - aRect.size.width += (l + r); - aRect.size.height += (t + b); - aRect.origin.x -= l; - aRect.origin.y -= b; - return aRect; + return [windowDecorator frameRectForContentRect: aRect + styleMask: aStyle]; } -+ (NSRect) minFrameWidthWithTitle: (NSString*)aTitle - styleMask: (unsigned int)aStyle ++ (float) minFrameWidthWithTitle: (NSString *)aTitle + styleMask: (unsigned int)aStyle { + if (!windowDecorator) + windowDecorator = [GSWindowDecorationView windowDecorator]; + + return [windowDecorator minFrameWidthWithTitle: aTitle + styleMask: aStyle]; + +#if 0 float t, b, l, r; NSRect f = NSZeroRect; @@ -585,6 +1285,7 @@ */ f.size.width += [aTitle length] * 10; return f; +#endif } /* default Screen and window depth */ @@ -706,7 +1407,7 @@ [super dealloc]; } -- (void) _initBackendWindow: (NSRect)frame +- (void) _initBackendWindow { int screenNumber; NSCountedSet *dragTypes; @@ -728,7 +1429,11 @@ } screenNumber = [_screen screenNumber]; - _windowNum = [srv window: frame : _backingType : _styleMask : screenNumber]; + _windowNum = + [srv window: _windowFrame + : _backingType + : _styleMask & (NSIconWindowMask | NSMiniWindowMask) + : screenNumber]; [srv setwindowlevel: [self level] : _windowNum]; NSMapInsert (windowmaps, (void*)_windowNum, self); @@ -738,9 +1443,9 @@ _gstate = GSDefineGState(context); DPSgrestore(context); - frame = [NSWindow contentRectForFrameRect: frame styleMask: _styleMask]; if (NSIsEmptyRect([_wv frame])) { + NSRect frame = _windowFrame; frame.origin = NSZeroPoint; [_wv setFrame: frame]; } @@ -776,8 +1481,6 @@ } /* Other stuff we need to do for deferred windows */ - if (_windowTitle != nil) - [srv titlewindow: _windowTitle : _windowNum]; if (!NSEqualSizes(_minimumSize, NSZeroSize)) [self setMinSize: _minimumSize]; if (!NSEqualSizes(_maximumSize, NSZeroSize)) @@ -785,8 +1488,8 @@ if (!NSEqualSizes(_increments, NSZeroSize)) [self setResizeIncrements: _increments]; - NSDebugLLog(@"NSWindow", @"Created NSWindow frame %@", - NSStringFromRect(_frame)); + NSDebugLLog(@"NSWindow", @"Created NSWindow window frame %@", + NSStringFromRect(_windowFrame)); } /* @@ -861,6 +1564,9 @@ windowmaps = NSCreateMapTable(NSIntMapKeyCallBacks, NSNonRetainedObjectMapValueCallBacks, 20); + if (!windowDecorator) + windowDecorator = [GSWindowDecorationView windowDecorator]; + /* Initialize attributes and flags */ [super init]; [self _initDefaults]; @@ -872,9 +1578,9 @@ ASSIGN(_screen, aScreen); _depthLimit = [_screen depth]; - _frame = [NSWindow frameRectForContentRect: contentRect styleMask: aStyle]; - _minimumSize = NSMakeSize(_frame.size.width - contentRect.size.width + 1, - _frame.size.height - contentRect.size.height + 1); + _windowFrame = [NSWindow frameRectForContentRect: contentRect styleMask: aStyle]; + _minimumSize = NSMakeSize(_windowFrame.size.width - contentRect.size.width + 1, + _windowFrame.size.height - contentRect.size.height + 1); _maximumSize = NSMakeSize (10e4, 10e4); [self setNextResponder: NSApp]; @@ -884,8 +1590,9 @@ /* Create the window view */ cframe.origin = NSZeroPoint; - cframe.size = contentRect.size; - _wv = [[GSWindowView allocWithZone: [self zone]] initWithFrame: cframe]; + cframe.size = _windowFrame.size; + _wv = [windowDecorator newWindowDecorationViewWithFrame: cframe + window: self]; [_wv viewWillMoveToWindow: self]; /* Create the content view */ @@ -904,10 +1611,10 @@ if (flag == NO) { NSDebugLLog(@"NSWindow", @"Creating NSWindow\n"); - [self _initBackendWindow: _frame]; + [self _initBackendWindow]; } else - NSDebugLLog(@"NSWindow", @"Defering NSWindow creation\n"); + NSDebugLLog(@"NSWindow", @"Deferring NSWindow creation\n"); NSDebugLLog(@"NSWindow", @"NSWindow end of init\n"); return self; @@ -928,21 +1635,18 @@ { if (aView == nil) { - aView = AUTORELEASE([[NSView alloc] initWithFrame: _frame]); + aView = AUTORELEASE([[NSView alloc] + initWithFrame: + [NSWindow contentRectForFrameRect: _windowFrame + styleMask: _styleMask]]); } if (_contentView != nil) { [_contentView removeFromSuperview]; } _contentView = aView; - [_contentView setAutoresizingMask: (NSViewWidthSizable - | NSViewHeightSizable)]; - [_wv addSubview: _contentView]; - [_contentView resizeWithOldSuperviewSize: [_contentView frame].size]; - [_contentView setFrameOrigin: [_wv bounds].origin]; - NSAssert1 ([[_wv subviews] count] == 1, - @"window's view has %d subviews!", [[_wv subviews] count]); + [_wv setContentView: _contentView]; [_contentView setNextResponder: self]; } @@ -975,14 +1679,13 @@ { if ([_windowTitle isEqual: aString] == NO) { - ASSIGN(_windowTitle, aString); - [self setMiniwindowTitle: aString]; - if (_windowNum > 0) - [GSServerForWindow(self) titlewindow: aString : _windowNum]; + ASSIGNCOPY(_windowTitle, aString); + [self setMiniwindowTitle: _windowTitle]; + [_wv setTitle: _windowTitle]; if (_f.menu_exclude == NO && _f.has_opened == YES) { [NSApp changeWindowsItem: self - title: aString + title: _windowTitle filename: NO]; } } @@ -996,14 +1699,13 @@ [aString stringByDeletingLastPathComponent]]; if ([_windowTitle isEqual: aString] == NO) { - ASSIGN(_windowTitle, aString); - [self setMiniwindowTitle: aString]; - if (_windowNum > 0) - [GSServerForWindow(self) titlewindow: aString : _windowNum]; + ASSIGNCOPY(_windowTitle, aString); + [self setMiniwindowTitle: _windowTitle]; + [_wv setTitle: _windowTitle]; if (_f.menu_exclude == NO && _f.has_opened == YES) { [NSApp changeWindowsItem: self - title: aString + title: _windowTitle filename: YES]; } } @@ -1234,7 +1936,7 @@ [_firstResponder becomeKeyWindow]; } - [GSServerForWindow(self) setinputstate: GSTitleBarKey : _windowNum]; + [_wv setInputState: GSTitleBarKey]; [GSServerForWindow(self) setinputfocus: _windowNum]; [self resetCursorRects]; [nc postNotificationName: NSWindowDidBecomeKeyNotification object: self]; @@ -1249,7 +1951,7 @@ _f.is_main = YES; if (_f.is_key == NO) { - [GSServerForWindow(self) setinputstate: GSTitleBarMain : _windowNum]; + [_wv setInputState: GSTitleBarMain]; } [nc postNotificationName: NSWindowDidBecomeMainNotification object: self]; NSDebugLLog(@"NSWindow", @"%@ is now main window", [self title]); @@ -1450,26 +2152,26 @@ && [NSApp isHidden] == NO && _f.visible == NO) { - NSRect nframe = [self constrainFrameRect: _frame + NSRect nframe = [self constrainFrameRect: _windowFrame toScreen: [self screen]]; if (_windowNum) [self setFrame: nframe display: NO]; else - _frame = nframe; + _windowFrame = nframe; } // create deferred window if (_windowNum == 0) { - [self _initBackendWindow: _frame]; + [self _initBackendWindow]; display = YES; } } // Draw content before backend window ordering if (display) - [_contentView display]; + [_wv display]; else if (place != NSWindowOut) - [_contentView displayIfNeeded]; + [_wv displayIfNeeded]; /* The backend will keep us below the current key window unless we force it not too */ @@ -1516,7 +2218,7 @@ } if ([self isKeyWindow] == YES) { - [srv setinputstate: GSTitleBarKey : _windowNum]; + [_wv setInputState: GSTitleBarKey]; [srv setinputfocus: _windowNum]; } _f.visible = YES; @@ -1539,12 +2241,11 @@ if (_f.is_main == YES) { - [GSServerForWindow(self) setinputstate: GSTitleBarMain : _windowNum]; + [_wv setInputState: GSTitleBarMain]; } else { - [GSServerForWindow(self) setinputstate: GSTitleBarNormal - : _windowNum]; + [_wv setInputState: GSTitleBarNormal]; } [self discardCursorRects]; @@ -1559,13 +2260,11 @@ _f.is_main = NO; if (_f.is_key == YES) { - [GSServerForWindow(self) setinputstate: GSTitleBarKey - : _windowNum]; + [_wv setInputState: GSTitleBarKey]; } else { - [GSServerForWindow(self) setinputstate: GSTitleBarNormal - : _windowNum]; + [_wv setInputState: GSTitleBarNormal]; } [nc postNotificationName: NSWindowDidResignMainNotification object: self]; } @@ -1639,10 +2338,10 @@ - (void) center { NSSize screenSize = [[self screen] frame].size; - NSPoint origin = _frame.origin; + NSPoint origin = _windowFrame.origin; - origin.x = (screenSize.width - _frame.size.width) / 2; - origin.y = (screenSize.height - _frame.size.height) / 2; + origin.x = (screenSize.width - _windowFrame.size.width) / 2; + origin.y = (screenSize.height - _windowFrame.size.height) / 2; [self setFrameOrigin: origin]; } @@ -1695,7 +2394,7 @@ - (NSRect) frame { - return _frame; + return _windowFrame; } - (NSSize) minSize @@ -1710,11 +2409,11 @@ - (void) setContentSize: (NSSize)aSize { - NSRect r = _frame; + NSRect r = _windowFrame; r.size = aSize; r = [NSWindow frameRectForContentRect: r styleMask: _styleMask]; - r.origin = _frame.origin; + r.origin = _windowFrame.origin; [self setFrame: r display: YES]; } @@ -1737,7 +2436,7 @@ frameRect.size.height = _minimumSize.height; } - if (NSEqualSizes(frameRect.size, _frame.size) == NO) + if (NSEqualSizes(frameRect.size, _windowFrame.size) == NO) { /* Windows need to be constrained when displayed or resized - but only titled windows are constrained */ @@ -1755,10 +2454,10 @@ } // If nothing changes, don't send it to the backend and don't redisplay - if (NSEqualRects(_frame, frameRect)) + if (NSEqualRects(_windowFrame, frameRect)) return; - if (NSEqualPoints(_frame.origin, frameRect.origin) == NO) + if (NSEqualPoints(_windowFrame.origin, frameRect.origin) == NO) [nc postNotificationName: NSWindowWillMoveNotification object: self]; /* @@ -1769,9 +2468,7 @@ [GSServerForWindow(self) placewindow: frameRect : _windowNum]; else { - _frame = frameRect; - frameRect = [NSWindow contentRectForFrameRect: frameRect - styleMask: _styleMask]; + _windowFrame = frameRect; frameRect.origin = NSZeroPoint; [_wv setFrame: frameRect]; } @@ -1782,7 +2479,7 @@ - (void) setFrameOrigin: (NSPoint)aPoint { - NSRect r = _frame; + NSRect r = _windowFrame; r.origin = aPoint; [self setFrame: r display: NO]; @@ -1790,10 +2487,10 @@ - (void) setFrameTopLeftPoint: (NSPoint)aPoint { - NSRect r = _frame; + NSRect r = _windowFrame; r.origin = aPoint; - r.origin.y -= _frame.size.height; + r.origin.y -= _windowFrame.size.height; [self setFrame: r display: NO]; } @@ -1851,14 +2548,9 @@ */ - (NSPoint) convertBaseToScreen: (NSPoint)aPoint { - GSDisplayServer *srv = GSCurrentServer(); - NSPoint screenPoint; - float t, b, l, r; - - [srv styleoffsets: &l : &r : &t : &b : _styleMask]; - screenPoint.x = _frame.origin.x + aPoint.x + l; - screenPoint.y = _frame.origin.y + aPoint.y + b; - + NSPoint screenPoint; + screenPoint.x = _windowFrame.origin.x + aPoint.x; + screenPoint.y = _windowFrame.origin.y + aPoint.y; return screenPoint; } @@ -1868,14 +2560,9 @@ */ - (NSPoint) convertScreenToBase: (NSPoint)aPoint { - GSDisplayServer *srv = GSCurrentServer(); - NSPoint basePoint; - float t, b, l, r; - - [srv styleoffsets: &l : &r : &t : &b : _styleMask]; - basePoint.x = aPoint.x - _frame.origin.x - l; - basePoint.y = aPoint.y - _frame.origin.y - b; - + NSPoint basePoint; + basePoint.x = aPoint.x - _windowFrame.origin.x; + basePoint.y = aPoint.y - _windowFrame.origin.y; return basePoint; } @@ -2320,7 +3007,7 @@ /* Make sure we're not defered */ if (_windowNum == 0) { - [self _initBackendWindow: _frame]; + [self _initBackendWindow]; } /* * Ensure that we have a miniwindow counterpart. @@ -2460,8 +3147,7 @@ { [NSApp updateWindowsItem: self]; } - if (_windowNum) - [GSServerForWindow(self) docedited: flag : _windowNum]; + [_wv setDocumentEdited: flag]; } } @@ -2879,7 +3565,8 @@ /** Handles mouse and other events sent to the receiver by NSApplication. Do not invoke this method directly. */ -- (void) sendEvent: (NSEvent*)theEvent +- (void) _sendEvent: (NSEvent*)theEvent + becomesKeyOnlyIfNeeded: (BOOL)becomesKeyOnlyIfNeeded { NSView *v; NSEventType type; @@ -2914,10 +3601,12 @@ if (_f.has_closed == NO) { - v = [_contentView hitTest: [theEvent locationInWindow]]; + v = [_wv hitTest: [theEvent locationInWindow]]; if (_f.is_key == NO) { - [self makeKeyAndOrderFront: self]; + /* NSPanel modification: check becomesKeyOnlyIfNeeded. */ + if (!becomesKeyOnlyIfNeeded || [v needsPanelToBecomeKey]) + [self makeKeyAndOrderFront: self]; } /* Activate the app *after* making the receiver key, as app activation tries to make the previous key window key. */ @@ -2964,27 +3653,27 @@ break; case NSOtherMouseDown: - v = [_contentView hitTest: [theEvent locationInWindow]]; + v = [_wv hitTest: [theEvent locationInWindow]]; [v otherMouseDown: theEvent]; _lastPoint = [theEvent locationInWindow]; break; case NSOtherMouseUp: - v = [_contentView hitTest: [theEvent locationInWindow]]; + v = [_wv hitTest: [theEvent locationInWindow]]; [v otherMouseUp: theEvent]; _lastPoint = [theEvent locationInWindow]; break; case NSRightMouseDown: { - v = [_contentView hitTest: [theEvent locationInWindow]]; + v = [_wv hitTest: [theEvent locationInWindow]]; [v rightMouseDown: theEvent]; _lastPoint = [theEvent locationInWindow]; } break; case NSRightMouseUp: - v = [_contentView hitTest: [theEvent locationInWindow]]; + v = [_wv hitTest: [theEvent locationInWindow]]; [v rightMouseUp: theEvent]; _lastPoint = [theEvent locationInWindow]; break; @@ -2996,15 +3685,15 @@ switch (type) { case NSLeftMouseDragged: - v = [_contentView hitTest: [theEvent locationInWindow]]; + v = [_wv hitTest: [theEvent locationInWindow]]; [v mouseDragged: theEvent]; break; case NSOtherMouseDragged: - v = [_contentView hitTest: [theEvent locationInWindow]]; + v = [_wv hitTest: [theEvent locationInWindow]]; [v otherMouseDragged: theEvent]; break; case NSRightMouseDragged: - v = [_contentView hitTest: [theEvent locationInWindow]]; + v = [_wv hitTest: [theEvent locationInWindow]]; [v rightMouseDragged: theEvent]; break; default: @@ -3014,7 +3703,7 @@ * If the window is set to accept mouse movements, we need to * forward the mouse movement to the correct view. */ - v = [_contentView hitTest: [theEvent locationInWindow]]; + v = [_wv hitTest: [theEvent locationInWindow]]; [v mouseMoved: theEvent]; } break; @@ -3025,7 +3714,7 @@ * a tracking rectangle then we need to determine if we should send * a NSMouseEntered or NSMouseExited event. */ - (*ctImp)(self, ctSel, _contentView, theEvent); + (*ctImp)(self, ctSel, _wv, theEvent); if (_f.is_key) { @@ -3035,7 +3724,7 @@ * cursor update event. */ if (_f.cursor_rects_enabled) - (*ccImp)(self, ccSel, _contentView, theEvent); + (*ccImp)(self, ccSel, _wv, theEvent); } _lastPoint = [theEvent locationInWindow]; @@ -3074,7 +3763,7 @@ break; case NSScrollWheel: - v = [_contentView hitTest: [theEvent locationInWindow]]; + v = [_wv hitTest: [theEvent locationInWindow]]; [v scrollWheel: theEvent]; break; @@ -3088,10 +3777,10 @@ switch (sub) { case GSAppKitWindowMoved: - _frame.origin.x = (float)[theEvent data1]; - _frame.origin.y = (float)[theEvent data2]; + _windowFrame.origin.x = (float)[theEvent data1]; + _windowFrame.origin.y = (float)[theEvent data2]; NSDebugLLog(@"Moving", @"Move event: %d %@", - _windowNum, NSStringFromPoint(_frame.origin)); + _windowNum, NSStringFromPoint(_windowFrame.origin)); if (_autosaveName != nil) { [self saveFrameUsingName: _autosaveName]; @@ -3101,20 +3790,18 @@ break; case GSAppKitWindowResized: - _frame.size.width = (float)[theEvent data1]; - _frame.size.height = (float)[theEvent data2]; + _windowFrame.size.width = (float)[theEvent data1]; + _windowFrame.size.height = (float)[theEvent data2]; /* Resize events always move the frame origin. The new origin is stored in the event location field */ - _frame.origin = [theEvent locationInWindow]; + _windowFrame.origin = [theEvent locationInWindow]; if (_autosaveName != nil) { [self saveFrameUsingName: _autosaveName]; } { - NSRect rect = _frame; + NSRect rect = _windowFrame; - rect = [NSWindow contentRectForFrameRect: rect - styleMask: _styleMask]; rect.origin = NSZeroPoint; [_wv setFrame: rect]; [_wv setNeedsDisplay: YES]; @@ -3169,7 +3856,7 @@ * We need to go through all of the views, and if there * is any with a tracking rectangle then we need to * determine if we should send a NSMouseExited event. */ - (*ctImp)(self, ctSel, _contentView, theEvent); + (*ctImp)(self, ctSel, _wv, theEvent); if (_f.is_key) { @@ -3179,7 +3866,7 @@ * to determine if we should send a cursor update * event. */ if (_f.cursor_rects_enabled) - (*ccImp)(self, ccSel, _contentView, theEvent); + (*ccImp)(self, ccSel, _wv, theEvent); } _lastPoint = NSMakePoint(-1, -1); @@ -3243,7 +3930,7 @@ { BOOL isEntry; - v = [_contentView hitTest: [theEvent locationInWindow]]; + v = [_wv hitTest: [theEvent locationInWindow]]; while (v != nil && ((NSViewPtr)v)->_rFlags.has_draginfo == 0) { v = [v superview]; @@ -3379,6 +4066,16 @@ } } +/** Handles mouse and other events sent to the receiver by NSApplication. + Do not invoke this method directly. +*/ +- (void) sendEvent: (NSEvent*)theEvent +{ + [self _sendEvent: theEvent + becomesKeyOnlyIfNeeded: NO]; +} + + - (BOOL) tryToPerform: (SEL)anAction with: (id)anObject { if ([super tryToPerform: anAction with: anObject]) @@ -3764,7 +4461,7 @@ NSRect fRect; NSRect sRect; - fRect = _frame; + fRect = _windowFrame; /* * The screen rectangle should gives the area of the screen in which @@ -3784,24 +4481,24 @@ */ - (NSData *) dataWithEPSInsideRect: (NSRect)rect { - return [_contentView dataWithEPSInsideRect: - [_contentView convertRect: rect fromView: nil]]; + return [_wv dataWithEPSInsideRect: + [_wv convertRect: rect fromView: nil]]; } - (NSData *)dataWithPDFInsideRect:(NSRect)aRect { - return [_contentView dataWithPDFInsideRect: - [_contentView convertRect: aRect fromView: nil]]; + return [_wv dataWithPDFInsideRect: + [_wv convertRect: aRect fromView: nil]]; } - (void) fax: (id)sender { - [_contentView fax: sender]; + [_wv fax: sender]; } - (void) print: (id)sender { - [_contentView print: sender]; + [_wv print: sender]; } /* @@ -3838,10 +4535,10 @@ maxRect = [self constrainFrameRect: maxRect toScreen: [self screen]]; // Compare the new frame with the current one - if ((abs(NSMaxX(maxRect) - NSMaxX(_frame)) < DIST) && - (abs(NSMaxY(maxRect) - NSMaxY(_frame)) < DIST) && - (abs(NSMinX(maxRect) - NSMinX(_frame)) < DIST) && - (abs(NSMinY(maxRect) - NSMinY(_frame)) < DIST)) + if ((abs(NSMaxX(maxRect) - NSMaxX(_windowFrame)) < DIST) && + (abs(NSMaxY(maxRect) - NSMaxY(_windowFrame)) < DIST) && + (abs(NSMinX(maxRect) - NSMinX(_windowFrame)) < DIST) && + (abs(NSMinY(maxRect) - NSMinY(_windowFrame)) < DIST)) { // Already in zoomed mode, reset user frame, if stored if (_autosaveName != nil) @@ -4078,8 +4775,7 @@ { // assign and setup the toolbar... ASSIGN(_toolbar, toolbar); - _toolbarView = [GSToolbarView initWithToolbar: _toolbar]; - +// _toolbarView = [GSToolbarView initWithToolbar: _toolbar]; } - (NSToolbar *) toolbar @@ -4137,18 +4833,6 @@ - (void) _releaseMouse: sender { [GSCurrentServer() releasemouse]; -} - -- (void) setContentViewSize: (NSSize)aSize -{ - NSRect r; - - r.origin = NSZeroPoint; - r.size = aSize; - if (_contentView) - { - [_contentView setFrame: r]; - } } - (void) _setVisible: (BOOL)flag