Window frame handling fixups (bug #17377)

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@23399 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2006-09-06 11:29:20 +00:00
parent a4ef3482cc
commit 56635aac0e
7 changed files with 246 additions and 257 deletions

View file

@ -1,3 +1,16 @@
2006-09-06 Richard Frith-Macdonald <rfm@gnu.org>
* Headers/AppKit/NSWindow.h: Add some documentation about what
frame management methods should do. Remove some bogus additional
methods for messing with frames.
* Source/NSWindow.m: ([cascadeTopLeftFromPoint:]) implement to match
MacOS-X specification. Remove unused additional frame methods.
* Source/GSWindowDecorationView.h:
* Source/GSWindowDecorationView.m:
* Source/GSStandardWindowDecorationView.m:
Remove unused/unnecessary methods and simplify.
NB. These fixups require corresponding fixups in the backend.
2006-09-05 Richard Frith-Macdonald <rfm@gnu.org> 2006-09-05 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSBitmapImageRep+JPEG.m: Fix declaration position causing * Source/NSBitmapImageRep+JPEG.m: Fix declaration position causing

View file

@ -106,29 +106,21 @@ APPKIT_EXPORT NSSize NSTokenSize;
/* /*
A window really has three interesting frames: A window really has three interesting frames:
The screen frame. This is the frame of the _entire_ window on the screen, The window frame. This is the frame of the _entire_ window on the screen,
including all decorations and borders (regardless of where they come from). including all decorations and borders (regardless of where they come from).
(On X, we can only guess what the screen frame is.)
The window frame. This is the frame of the backend window for this window, The backend frame. This is the frame of the backend window for this window,
and is thus the base of the coordinate system for the window. IOW, it's and is thus the base of the coordinate system for the window. IOW, it's
the frame of the area we can draw into. the frame of the area the gui library internals can draw into.
The contect rect. This is the frame of the content view. The contect rect. This is the frame of the content view ... ie the frame
that an application using the GUI/AppKit API can draw into.
Wrt. size, ScreenFrame >= WindowFrame >= ContentRect. When -gui doesn't Wrt. size, Frame >= BackendFrame >= ContentRect. When -gui doesn't
manage the window decorations, WindowFrame == ContentRect. When -gui does manage the window decorations, BackendFrame == ContentRect. When -gui does
manage the window decorations, WindowFrame will include the decorations, manage the window decorations, BackendFrame will include the decorations,
and ScreenFrame == WindowFrame. and Frame == BackendFrame.
To get coordinate transforms and stuff right wrt. OpenStep, we really want
the window frame here.
For hysterical reasons, _frame used to be the screen frame. However, the
resulting inconsistencies caused a bunch of problems. Thus, _frame is the
window frame. The other rectangles/sizes passed around in NSWindow
methods are supposed to all be window frames.
*/ */
NSRect _frame; NSRect _frame;
@ -219,21 +211,27 @@ APPKIT_EXPORT NSSize NSTokenSize;
* Computing frame and content rectangles * Computing frame and content rectangles
*/ */
/* These methods convert between the various frames discussed above. */ /**
* Returns the rectangle which would be used for the content view of
* a window whose on-screen size and position is specified by aRect
* and which is decorated with the border and title etc given by aStyle.
*/
+ (NSRect) contentRectForFrameRect: (NSRect)aRect + (NSRect) contentRectForFrameRect: (NSRect)aRect
styleMask: (unsigned int)aStyle; styleMask: (unsigned int)aStyle;
/**
* Returns the rectangle which would be used for the on-screen frame of
* a window if that window had a content view occupying the rectangle aRect
* and was decorated with the border and title etc given by aStyle.
*/
+ (NSRect) frameRectForContentRect: (NSRect)aRect + (NSRect) frameRectForContentRect: (NSRect)aRect
styleMask: (unsigned int)aStyle; styleMask: (unsigned int)aStyle;
+ (NSRect) screenRectForFrameRect: (NSRect)aRect /**
styleMask: (unsigned int)aStyle; * Returns the smallest frame width that will fit the given title
* and style. This is the on-screen width of the window including
+ (NSRect) frameRectForScreenRect: (NSRect)aRect * decorations.
styleMask: (unsigned int)aStyle; */
/* Returns the smallest window width that will fit the given title and
style. */
+ (float) minFrameWidthWithTitle: (NSString *)aTitle + (float) minFrameWidthWithTitle: (NSString *)aTitle
styleMask: (unsigned int)aStyle; styleMask: (unsigned int)aStyle;
@ -252,22 +250,66 @@ style. */
defer: (BOOL)flag defer: (BOOL)flag
screen: (NSScreen*)aScreen; screen: (NSScreen*)aScreen;
/* /**
* Converting coordinates * Converts aPoint from the base coordinate system of the receiver
* to a point in the screen coordinate system.
*/ */
- (NSPoint) convertBaseToScreen: (NSPoint)aPoint; - (NSPoint) convertBaseToScreen: (NSPoint)aPoint;
/**
* Converts aPoint from the screen coordinate system to a point in
* the base coordinate system of the receiver.
*/
- (NSPoint) convertScreenToBase: (NSPoint)aPoint; - (NSPoint) convertScreenToBase: (NSPoint)aPoint;
/* /**
* Moving and resizing the window * Returns the frame of the receiver ... the rectangular area that the window
* (including any border, title, and other decorations) occupies on screen.
*/ */
- (NSRect) frame; - (NSRect) frame;
/**
* <p>Sets the frame for the receiver to frameRect and if flag is YES causes
* the window contents to be refreshed. The value of frameRect is the
* desired on-screen size and position of the window including all
* border/decoration.
* </p>
* <p>The size of the frame is constrained to the minimum and maximum
* sizes set for the receiver (if any).<br />
* Its position is constrained to be on screen if it is a titled window.
* </p>
*/
- (void) setFrame: (NSRect)frameRect - (void) setFrame: (NSRect)frameRect
display: (BOOL)flag; display: (BOOL)flag;
/**
* Sets the origin (bottom left corner) of the receiver's frame to be the
* specified point (in screen coordinates).
*/
- (void) setFrameOrigin: (NSPoint)aPoint; - (void) setFrameOrigin: (NSPoint)aPoint;
/**
* Sets the top left corner of the receiver's frame to be the
* specified point (in screen coordinates).
*/
- (void) setFrameTopLeftPoint: (NSPoint)aPoint; - (void) setFrameTopLeftPoint: (NSPoint)aPoint;
/**
* Sets the size of the receiver's content view to aSize, implicitly
* adjusting the size of the receiver's frame to match.
*/
- (void) setContentSize: (NSSize)aSize; - (void) setContentSize: (NSSize)aSize;
/**
* Positions the receiver at topLeftPoint (or if topLeftPoint is NSZeroPoint,
* leaves the receiver unmoved except for any necessary constraint to fit
* on screen).<br />
* Returns the position of the top left corner of the receivers content
* view (after repositioning), so that another window cascaded at the
* returned point will not obscure the title bar of the receiver.
*/
- (NSPoint) cascadeTopLeftFromPoint: (NSPoint)topLeftPoint; - (NSPoint) cascadeTopLeftFromPoint: (NSPoint)topLeftPoint;
- (void) center; - (void) center;
- (int) resizeFlags; - (int) resizeFlags;
#ifndef STRICT_OPENSTEP #ifndef STRICT_OPENSTEP
@ -309,7 +351,7 @@ style. */
- (NSString*) stringWithSavedFrame; - (NSString*) stringWithSavedFrame;
#ifndef STRICT_OPENSTEP #ifndef STRICT_OPENSTEP
- (BOOL) setFrameUsingName: (NSString *)name - (BOOL) setFrameUsingName: (NSString *)name
force: (BOOL)force; force: (BOOL)force;
#endif #endif
/* /*
@ -556,7 +598,7 @@ style. */
- (void) print: (id)sender; - (void) print: (id)sender;
- (NSData*) dataWithEPSInsideRect: (NSRect)rect; - (NSData*) dataWithEPSInsideRect: (NSRect)rect;
#ifndef STRICT_OPENSTEP #ifndef STRICT_OPENSTEP
- (NSData *)dataWithPDFInsideRect:(NSRect)aRect; - (NSData*) dataWithPDFInsideRect:(NSRect)aRect;
#endif #endif
/* /*

View file

@ -44,18 +44,22 @@
#define TITLE_HEIGHT 23.0 #define TITLE_HEIGHT 23.0
#define RESIZE_HEIGHT 9.0 #define RESIZE_HEIGHT 9.0
+(void) offsets: (float *)l : (float *)r : (float *)t : (float *)b + (void) offsets: (float *)l : (float *)r : (float *)t : (float *)b
forStyleMask: (unsigned int)style forStyleMask: (unsigned int)style
{ {
if (style if (style
& (NSTitledWindowMask | NSClosableWindowMask & (NSTitledWindowMask | NSClosableWindowMask
| NSMiniaturizableWindowMask | NSResizableWindowMask)) | NSMiniaturizableWindowMask | NSResizableWindowMask))
*l = *r = *t = *b = 1.0; {
*l = *r = *t = *b = 1.0;
}
else else
*l = *r = *t = *b = 0.0; {
*l = *r = *t = *b = 0.0;
}
if (style if (style
& (NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask)) & (NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask))
{ {
*t = TITLE_HEIGHT; *t = TITLE_HEIGHT;
} }
@ -65,24 +69,19 @@
} }
} }
+(void) screenOffsets: (float *)l : (float *)r : (float *)t : (float *)b
forStyleMask: (unsigned int)style
{
*l = *r = *r = *b = 0.0;
}
+ (float) minFrameWidthWithTitle: (NSString *)aTitle + (float) minFrameWidthWithTitle: (NSString *)aTitle
styleMask: (unsigned int)aStyle styleMask: (unsigned int)aStyle
{ {
float l, r, t, b, width; float l, r, t, b, width;
[self offsets: &l : &r : &t : &b
forStyleMask: aStyle]; [self offsets: &l : &r : &t : &b forStyleMask: aStyle];
width = l + r; width = l + r;
if (aStyle & NSTitledWindowMask) if (aStyle & NSTitledWindowMask)
width += [aTitle sizeWithAttributes: nil].width; {
width += [aTitle sizeWithAttributes: nil].width;
}
return width; return width;
} }
@ -90,14 +89,17 @@
static NSDictionary *titleTextAttributes[3]; static NSDictionary *titleTextAttributes[3];
static NSColor *titleColor[3]; static NSColor *titleColor[3];
-(void) updateRects - (void) updateRects
{ {
if (hasTitleBar) if (hasTitleBar)
titleBarRect = NSMakeRect(0.0, _frame.size.height - TITLE_HEIGHT, {
_frame.size.width, TITLE_HEIGHT); titleBarRect = NSMakeRect(0.0, _frame.size.height - TITLE_HEIGHT,
_frame.size.width, TITLE_HEIGHT);
}
if (hasResizeBar) if (hasResizeBar)
resizeBarRect = NSMakeRect(0.0, 0.0, _frame.size.width, RESIZE_HEIGHT); {
resizeBarRect = NSMakeRect(0.0, 0.0, _frame.size.width, RESIZE_HEIGHT);
}
if (hasCloseButton) if (hasCloseButton)
{ {
closeButtonRect = NSMakeRect( closeButtonRect = NSMakeRect(
@ -107,18 +109,18 @@ static NSColor *titleColor[3];
if (hasMiniaturizeButton) if (hasMiniaturizeButton)
{ {
miniaturizeButtonRect = NSMakeRect(4, _frame.size.height - 15 - 4, miniaturizeButtonRect = NSMakeRect(
15, 15); 4, _frame.size.height - 15 - 4, 15, 15);
[miniaturizeButton setFrame: miniaturizeButtonRect]; [miniaturizeButton setFrame: miniaturizeButtonRect];
} }
} }
- initWithFrame: (NSRect)frame - (id) initWithFrame: (NSRect)frame
window: (NSWindow *)w window: (NSWindow *)w
{ {
if (!titleTextAttributes[0]) if (!titleTextAttributes[0])
{ {
NSMutableParagraphStyle *p; NSMutableParagraphStyle *p;
p = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; p = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
[p setLineBreakMode: NSLineBreakByClipping]; [p setLineBreakMode: NSLineBreakByClipping];
@ -129,12 +131,14 @@ static NSColor *titleColor[3];
[NSColor windowFrameTextColor], NSForegroundColorAttributeName, [NSColor windowFrameTextColor], NSForegroundColorAttributeName,
p, NSParagraphStyleAttributeName, p, NSParagraphStyleAttributeName,
nil]; nil];
titleTextAttributes[1] = [[NSMutableDictionary alloc] titleTextAttributes[1] = [[NSMutableDictionary alloc]
initWithObjectsAndKeys: initWithObjectsAndKeys:
[NSFont titleBarFontOfSize: 0], NSFontAttributeName, [NSFont titleBarFontOfSize: 0], NSFontAttributeName,
[NSColor blackColor], NSForegroundColorAttributeName, /* TODO: need a named color for this */ [NSColor blackColor], NSForegroundColorAttributeName, /* TODO: need a named color for this */
p, NSParagraphStyleAttributeName, p, NSParagraphStyleAttributeName,
nil]; nil];
titleTextAttributes[2] = [[NSMutableDictionary alloc] titleTextAttributes[2] = [[NSMutableDictionary alloc]
initWithObjectsAndKeys: initWithObjectsAndKeys:
[NSFont titleBarFontOfSize: 0], NSFontAttributeName, [NSFont titleBarFontOfSize: 0], NSFontAttributeName,
@ -148,18 +152,18 @@ static NSColor *titleColor[3];
titleColor[2] = RETAIN([NSColor darkGrayColor]); titleColor[2] = RETAIN([NSColor darkGrayColor]);
} }
self = [super initWithFrame: frame self = [super initWithFrame: frame window: w];
window: w];
if (!self) return nil; if (!self) return nil;
if ([w styleMask] if ([w styleMask]
& (NSTitledWindowMask | NSClosableWindowMask & (NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask))
| NSMiniaturizableWindowMask))
{ {
hasTitleBar = YES; hasTitleBar = YES;
} }
if ([w styleMask] & NSTitledWindowMask) if ([w styleMask] & NSTitledWindowMask)
isTitled = YES; {
isTitled = YES;
}
if ([w styleMask] & NSClosableWindowMask) if ([w styleMask] & NSClosableWindowMask)
{ {
hasCloseButton = YES; hasCloseButton = YES;
@ -200,17 +204,18 @@ static NSColor *titleColor[3];
RELEASE(miniaturizeButton); RELEASE(miniaturizeButton);
} }
if ([w styleMask] & NSResizableWindowMask) if ([w styleMask] & NSResizableWindowMask)
hasResizeBar = YES; {
hasResizeBar = YES;
}
[self updateRects]; [self updateRects];
return self; return self;
} }
-(void) drawTitleBar - (void) drawTitleBar
{ {
static const NSRectEdge edges[4] = {NSMinXEdge, NSMaxYEdge, static const NSRectEdge edges[4] = {NSMinXEdge, NSMaxYEdge,
NSMaxXEdge, NSMinYEdge}; NSMaxXEdge, NSMinYEdge};
float grays[3][4] = float grays[3][4] =
{{NSLightGray, NSLightGray, NSDarkGray, NSDarkGray}, {{NSLightGray, NSLightGray, NSDarkGray, NSDarkGray},
@ -271,7 +276,7 @@ static const NSRectEdge edges[4] = {NSMinXEdge, NSMaxYEdge,
} }
} }
-(void) drawResizeBar - (void) drawResizeBar
{ {
[[NSColor lightGrayColor] set]; [[NSColor lightGrayColor] set];
PSrectfill(1.0, 1.0, resizeBarRect.size.width - 2.0, RESIZE_HEIGHT - 3.0); PSrectfill(1.0, 1.0, resizeBarRect.size.width - 2.0, RESIZE_HEIGHT - 3.0);
@ -313,7 +318,7 @@ static const NSRectEdge edges[4] = {NSMinXEdge, NSMaxYEdge,
PSstroke(); PSstroke();
} }
-(void) drawRect: (NSRect)rect - (void) drawRect: (NSRect)rect
{ {
if (hasTitleBar && NSIntersectsRect(rect, titleBarRect)) if (hasTitleBar && NSIntersectsRect(rect, titleBarRect))
{ {
@ -359,14 +364,14 @@ static const NSRectEdge edges[4] = {NSMinXEdge, NSMaxYEdge,
} }
-(void) setTitle: (NSString *)newTitle - (void) setTitle: (NSString *)newTitle
{ {
if (isTitled) if (isTitled)
[self setNeedsDisplayInRect: titleBarRect]; [self setNeedsDisplayInRect: titleBarRect];
[super setTitle: newTitle]; [super setTitle: newTitle];
} }
-(void) setInputState: (int)state - (void) setInputState: (int)state
{ {
NSAssert(state >= 0 && state <= 2, @"Invalid state!"); NSAssert(state >= 0 && state <= 2, @"Invalid state!");
[super setInputState: state]; [super setInputState: state];
@ -374,7 +379,7 @@ static const NSRectEdge edges[4] = {NSMinXEdge, NSMaxYEdge,
[self setNeedsDisplayInRect: titleBarRect]; [self setNeedsDisplayInRect: titleBarRect];
} }
-(void) setDocumentEdited: (BOOL)flag - (void) setDocumentEdited: (BOOL)flag
{ {
if (flag) if (flag)
{ {
@ -392,14 +397,14 @@ static const NSRectEdge edges[4] = {NSMinXEdge, NSMaxYEdge,
} }
-(NSPoint) mouseLocationOnScreenOutsideOfEventStream - (NSPoint) mouseLocationOnScreenOutsideOfEventStream
{ {
int screen = [[window screen] screenNumber]; int screen = [[window screen] screenNumber];
return [GSServerForWindow(window) mouseLocationOnScreen: screen return [GSServerForWindow(window) mouseLocationOnScreen: screen
window: NULL]; window: NULL];
} }
-(void) moveWindowStartingWithEvent: (NSEvent *)event - (void) moveWindowStartingWithEvent: (NSEvent *)event
{ {
unsigned int mask = NSLeftMouseDraggedMask | NSLeftMouseUpMask; unsigned int mask = NSLeftMouseDraggedMask | NSLeftMouseUpMask;
NSEvent *currentEvent = event; NSEvent *currentEvent = event;
@ -436,8 +441,9 @@ static const NSRectEdge edges[4] = {NSMinXEdge, NSMaxYEdge,
} }
static NSRect calc_new_frame(NSRect frame, NSPoint point, NSPoint firstPoint, static NSRect
int mode, NSSize minSize, NSSize maxSize) calc_new_frame(NSRect frame, NSPoint point, NSPoint firstPoint,
int mode, NSSize minSize, NSSize maxSize)
{ {
NSRect newFrame = frame; NSRect newFrame = frame;
newFrame.origin.y = point.y - firstPoint.y; newFrame.origin.y = point.y - firstPoint.y;
@ -473,7 +479,7 @@ static NSRect calc_new_frame(NSRect frame, NSPoint point, NSPoint firstPoint,
return newFrame; return newFrame;
} }
-(void) resizeWindowStartingWithEvent: (NSEvent *)event - (void) resizeWindowStartingWithEvent: (NSEvent *)event
{ {
unsigned int mask = NSLeftMouseDraggedMask | NSLeftMouseUpMask; unsigned int mask = NSLeftMouseDraggedMask | NSLeftMouseUpMask;
NSEvent *currentEvent = event; NSEvent *currentEvent = event;
@ -517,7 +523,8 @@ static NSRect calc_new_frame(NSRect frame, NSPoint point, NSPoint firstPoint,
} }
point = [self mouseLocationOnScreenOutsideOfEventStream]; point = [self mouseLocationOnScreenOutsideOfEventStream];
newFrame = calc_new_frame(frame, point, firstPoint, mode, minSize, maxSize); newFrame
= calc_new_frame(frame, point, firstPoint, mode, minSize, maxSize);
if (currentEvent && [currentEvent type] == NSLeftMouseUp) if (currentEvent && [currentEvent type] == NSLeftMouseUp)
break; break;
@ -532,12 +539,12 @@ static NSRect calc_new_frame(NSRect frame, NSPoint point, NSPoint firstPoint,
[window setFrame: newFrame display: YES]; [window setFrame: newFrame display: YES];
} }
-(BOOL) acceptsFirstMouse: (NSEvent*)theEvent - (BOOL) acceptsFirstMouse: (NSEvent*)theEvent
{ {
return YES; return YES;
} }
-(void) mouseDown: (NSEvent *)event - (void) mouseDown: (NSEvent *)event
{ {
NSPoint p = [self convertPoint: [event locationInWindow] fromView: nil]; NSPoint p = [self convertPoint: [event locationInWindow] fromView: nil];

View file

@ -39,10 +39,6 @@
styleMask: (unsigned int)aStyle; styleMask: (unsigned int)aStyle;
- (NSRect) frameRectForContentRect: (NSRect)aRect - (NSRect) frameRectForContentRect: (NSRect)aRect
styleMask: (unsigned int)aStyle; styleMask: (unsigned int)aStyle;
- (NSRect) screenRectForFrameRect: (NSRect)aRect
styleMask: (unsigned int)aStyle;
- (NSRect) frameRectForScreenRect: (NSRect)aRect
styleMask: (unsigned int)aStyle;
- (float) minFrameWidthWithTitle: (NSString *)aTitle - (float) minFrameWidthWithTitle: (NSString *)aTitle
styleMask: (unsigned int)aStyle; styleMask: (unsigned int)aStyle;
@end @end
@ -63,23 +59,22 @@ this, either directly, or indirectly (by using the backend).
int inputState; int inputState;
BOOL documentEdited; BOOL documentEdited;
} }
+(id<GSWindowDecorator>) windowDecorator; + (id<GSWindowDecorator>) windowDecorator;
- initWithFrame: (NSRect)frame - (id) initWithFrame: (NSRect)frame window: (NSWindow *)w;
window: (NSWindow *)w;
-(void) setContentView: (NSView *)contentView; - (void) setBackgroundColor: (NSColor *)color;
- (void) setContentView: (NSView *)contentView;
- (void) setDocumentEdited: (BOOL)flag;
- (void) setInputState: (int)state;
- (void) setTitle: (NSString *)title;
/* /*
Called when the backend window is created or destroyed. When it's destroyed, Called when the backend window is created or destroyed. When it's destroyed,
windowNumber will be 0. windowNumber will be 0.
*/ */
-(void) setWindowNumber: (int)windowNumber; - (void) setWindowNumber: (int)windowNumber;
-(void) setTitle: (NSString *)title;
-(void) setInputState: (int)state;
-(void) setDocumentEdited: (BOOL)flag;
-(void) setBackgroundColor: (NSColor *)color;
@end @end

View file

@ -38,20 +38,16 @@ struct NSWindow_struct
}; };
/* /* Manage window decorations by using the backend functions. This only works
Manage window decorations by using the backend functions. This only works * on backends that can handle window decorations.
on backends that can handle window decorations. */
*/
@interface GSBackendWindowDecorationView : GSWindowDecorationView @interface GSBackendWindowDecorationView : GSWindowDecorationView
@end @end
/*
GSWindowDecorationView implementation.
*/
@implementation GSWindowDecorationView @implementation GSWindowDecorationView
+(id<GSWindowDecorator>) windowDecorator + (id<GSWindowDecorator>) windowDecorator
{ {
if ([GSCurrentServer() handlesWindowDecorations]) if ([GSCurrentServer() handlesWindowDecorations])
return [GSBackendWindowDecorationView self]; return [GSBackendWindowDecorationView self];
@ -60,22 +56,16 @@ GSWindowDecorationView implementation.
} }
+(id) newWindowDecorationViewWithFrame: (NSRect)frame + (id) newWindowDecorationViewWithFrame: (NSRect)frame
window: (NSWindow *)aWindow window: (NSWindow *)aWindow
{ {
return [[self alloc] initWithFrame: frame return [[self alloc] initWithFrame: frame
window: aWindow]; window: aWindow];
} }
+(void) offsets: (float *)l : (float *)r : (float *)t : (float *)b + (void) offsets: (float *)l : (float *)r : (float *)t : (float *)b
forStyleMask: (unsigned int)style forStyleMask: (unsigned int)style
{
[self subclassResponsibility: _cmd];
}
+(void) screenOffsets: (float *)l : (float *)r : (float *)t : (float *)b
forStyleMask: (unsigned int)style
{ {
[self subclassResponsibility: _cmd]; [self subclassResponsibility: _cmd];
} }
@ -85,8 +75,7 @@ GSWindowDecorationView implementation.
{ {
float t, b, l, r; float t, b, l, r;
[self offsets: &l : &r : &t : &b [self offsets: &l : &r : &t : &b forStyleMask: aStyle];
forStyleMask: aStyle];
aRect.size.width -= l + r; aRect.size.width -= l + r;
aRect.size.height -= t + b; aRect.size.height -= t + b;
aRect.origin.x += l; aRect.origin.x += l;
@ -99,8 +88,7 @@ GSWindowDecorationView implementation.
{ {
float t, b, l, r; float t, b, l, r;
[self offsets: &l : &r : &t : &b [self offsets: &l : &r : &t : &b forStyleMask: aStyle];
forStyleMask: aStyle];
aRect.size.width += l + r; aRect.size.width += l + r;
aRect.size.height += t + b; aRect.size.height += t + b;
aRect.origin.x -= l; aRect.origin.x -= l;
@ -108,34 +96,6 @@ GSWindowDecorationView implementation.
return aRect; return aRect;
} }
+ (NSRect) screenRectForFrameRect: (NSRect)aRect
styleMask: (unsigned int)aStyle
{
float t, b, l, r;
[self screenOffsets: &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) frameRectForScreenRect: (NSRect)aRect
styleMask: (unsigned int)aStyle
{
float t, b, l, r;
[self screenOffsets: &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 + (float) minFrameWidthWithTitle: (NSString *)aTitle
styleMask: (unsigned int)aStyle styleMask: (unsigned int)aStyle
{ {
@ -144,73 +104,46 @@ GSWindowDecorationView implementation.
} }
/* + (NSRect) decorationRectForFrameRect: (NSRect)aRect
Internal helpers.
Returns the internal window frame rect for a given (screen) frame.
*/
+(NSRect) windowFrameRectForFrameRect: (NSRect)aRect
styleMask: (unsigned int)aStyle styleMask: (unsigned int)aStyle
{ {
aRect.origin = NSZeroPoint; aRect.origin = NSZeroPoint;
return aRect; return aRect;
} }
/* + (NSRect) contentRectForDecorationRect: (NSRect)aRect
Returns the content rect for a given window frame.
*/
+(NSRect) contentRectForWindowFrameRect: (NSRect)aRect
styleMask: (unsigned int)aStyle styleMask: (unsigned int)aStyle
{ {
return [self contentRectForFrameRect: aRect styleMask: aStyle]; return [self contentRectForFrameRect: aRect styleMask: aStyle];
} }
- initWithFrame: (NSRect)frame - (id) initWithFrame: (NSRect)frame
{ {
NSAssert(NO, @"Tried to create GSWindowDecorationView without a window!"); NSAssert(NO, @"Tried to create GSWindowDecorationView without a window!");
return nil; return nil;
} }
- initWithFrame: (NSRect)frame - (id) initWithFrame: (NSRect)frame
window: (NSWindow *)w window: (NSWindow *)w
{ {
frame = [isa windowFrameRectForFrameRect: frame unsigned int styleMask = [w styleMask];
styleMask: [w styleMask]];
frame = [isa decorationRectForFrameRect: frame
styleMask: styleMask];
self = [super initWithFrame: frame]; self = [super initWithFrame: frame];
if (!self) if (self != nil)
return nil; {
contentRect = [isa contentRectForDecorationRect: frame
window = w; styleMask: styleMask];
contentRect = frame; window = w;
contentRect = }
[isa contentRectForWindowFrameRect: contentRect
styleMask: [window styleMask]];
return self; return self;
} }
/* - (void) setBackgroundColor: (NSColor *)color
* Special setFrame: implementation - a minimal autoresize mechanism
*/
- (void) setFrame: (NSRect)frameRect
{ {
NSSize oldSize = _frame.size; [self setNeedsDisplayInRect: contentRect];
NSView *cv = [_window contentView];
frameRect = [isa windowFrameRectForFrameRect: frameRect
styleMask: [window styleMask]];
_autoresizes_subviews = NO;
[super setFrame: frameRect];
contentRect = [isa contentRectForWindowFrameRect: frameRect
styleMask: [window styleMask]];
// Safety Check.
[cv setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
[cv resizeWithOldSuperviewSize: oldSize];
} }
- (void) setContentView: (NSView *)contentView - (void) setContentView: (NSView *)contentView
@ -228,7 +161,49 @@ Returns the content rect for a given window frame.
contentRect.origin.y)]; contentRect.origin.y)];
} }
-(void) setWindowNumber: (int)theWindowNumber - (void) setDocumentEdited: (BOOL)flag
{
documentEdited = flag;
if (windowNumber)
[GSServerForWindow(window) docedited: documentEdited : windowNumber];
}
/*
* Special setFrame: implementation - a minimal autoresize mechanism
*/
- (void) setFrame: (NSRect)frameRect
{
NSSize oldSize = _frame.size;
NSView *cv = [_window contentView];
frameRect = [isa decorationRectForFrameRect: frameRect
styleMask: [window styleMask]];
_autoresizes_subviews = NO;
[super setFrame: frameRect];
contentRect = [isa contentRectForDecorationRect: frameRect
styleMask: [window styleMask]];
// Safety Check.
[cv setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
[cv resizeWithOldSuperviewSize: oldSize];
}
- (void) setInputState: (int)state
{
inputState = state;
if (windowNumber)
[GSServerForWindow(window) setinputstate: inputState : windowNumber];
}
- (void) setTitle: (NSString *)title
{
if (windowNumber)
[GSServerForWindow(window) titlewindow: title : windowNumber];
}
- (void) setWindowNumber: (int)theWindowNumber
{ {
windowNumber = theWindowNumber; windowNumber = theWindowNumber;
if (!windowNumber) if (!windowNumber)
@ -239,29 +214,6 @@ Returns the content rect for a given window frame.
[GSServerForWindow(window) docedited: documentEdited : windowNumber]; [GSServerForWindow(window) docedited: documentEdited : windowNumber];
} }
-(void) setTitle: (NSString *)title
{
if (windowNumber)
[GSServerForWindow(window) titlewindow: title : windowNumber];
}
-(void) setInputState: (int)state
{
inputState = state;
if (windowNumber)
[GSServerForWindow(window) setinputstate: inputState : windowNumber];
}
-(void) setDocumentEdited: (BOOL)flag
{
documentEdited = flag;
if (windowNumber)
[GSServerForWindow(window) docedited: documentEdited : windowNumber];
}
-(void) setBackgroundColor: (NSColor *)color
{
[self setNeedsDisplayInRect: contentRect];
}
- (BOOL) isOpaque - (BOOL) isOpaque
{ {
@ -279,14 +231,13 @@ Returns the content rect for a given window frame.
} }
} }
- (id) initWithCoder: (NSCoder*)aCoder
- initWithCoder: (NSCoder*)aCoder
{ {
NSAssert(NO, @"The top-level window view should never be encoded."); NSAssert(NO, @"The top-level window view should never be encoded.");
return nil; return nil;
} }
-(void) encodeWithCoder: (NSCoder*)aCoder
- (void) encodeWithCoder: (NSCoder*)aCoder
{ {
NSAssert(NO, @"The top-level window view should never be encoded."); NSAssert(NO, @"The top-level window view should never be encoded.");
} }
@ -297,14 +248,8 @@ Returns the content rect for a given window frame.
@implementation GSBackendWindowDecorationView @implementation GSBackendWindowDecorationView
+(void) offsets: (float *)l : (float *)r : (float *)t : (float *)b + (void) offsets: (float *)l : (float *)r : (float *)t : (float *)b
forStyleMask: (unsigned int)style forStyleMask: (unsigned int)style
{
*l = *r = *t = *b = 0.0;
}
+(void) screenOffsets: (float *)l : (float *)r : (float *)t : (float *)b
forStyleMask: (unsigned int)style
{ {
[GSCurrentServer() styleoffsets: l : r : t : b : style]; [GSCurrentServer() styleoffsets: l : r : t : b : style];
} }
@ -316,21 +261,19 @@ Returns the content rect for a given window frame.
return 0.0; return 0.0;
} }
+(NSRect) windowFrameRectForFrameRect: (NSRect)aRect + (NSRect) decorationRectForFrameRect: (NSRect)aRect
styleMask: (unsigned int)aStyle styleMask: (unsigned int)aStyle
{ {
float l, r, t, b; float l, r, t, b;
[self offsets: &l : &r : &t : &b forStyleMask: aStyle]; [self offsets: &l : &r : &t : &b forStyleMask: aStyle];
aRect.size.width -= l + r; aRect.size.width -= l + r;
aRect.size.height -= t + b; aRect.size.height -= t + b;
return aRect; return aRect;
} }
/* + (NSRect) contentRectForDecorationRect: (NSRect)aRect
Returns the content rect for a given window frame. styleMask: (unsigned int)aStyle
*/
+(NSRect) contentRectForWindowFrameRect: (NSRect)aRect
styleMask: (unsigned int)aStyle
{ {
return aRect; return aRect;
} }

View file

@ -307,7 +307,12 @@ static NSMutableArray *screenArray = nil;
switch (NSInterfaceStyleForKey(@"NSMenuInterfaceStyle", nil)) switch (NSInterfaceStyleForKey(@"NSMenuInterfaceStyle", nil))
{ {
case NSMacintoshInterfaceStyle: case NSMacintoshInterfaceStyle:
if ([NSApp mainMenu] != nil) if ([NSApp mainMenu] == nil)
{
// No menu yet ... assume a standard height
visFrame.size.height -= 23.0;
}
else
{ {
float menuHeight = [[[NSApp mainMenu] window] frame].size.height; float menuHeight = [[[NSApp mainMenu] window] frame].size.height;

View file

@ -616,26 +616,6 @@ static NSNotificationCenter *nc = nil;
styleMask: aStyle]; styleMask: aStyle];
} }
+ (NSRect) screenRectForFrameRect: (NSRect)aRect
styleMask: (unsigned int)aStyle
{
if (!windowDecorator)
windowDecorator = [GSWindowDecorationView windowDecorator];
return [windowDecorator screenRectForFrameRect: aRect
styleMask: aStyle];
}
+ (NSRect) frameRectForScreenRect: (NSRect)aRect
styleMask: (unsigned int)aStyle
{
if (!windowDecorator)
windowDecorator = [GSWindowDecorationView windowDecorator];
return [windowDecorator frameRectForScreenRect: aRect
styleMask: aStyle];
}
+ (float) minFrameWidthWithTitle: (NSString *)aTitle + (float) minFrameWidthWithTitle: (NSString *)aTitle
styleMask: (unsigned int)aStyle styleMask: (unsigned int)aStyle
{ {
@ -1706,16 +1686,20 @@ many times.
} }
} }
/*
* Moving and resizing the window
*/
- (NSPoint) cascadeTopLeftFromPoint: (NSPoint)topLeftPoint - (NSPoint) cascadeTopLeftFromPoint: (NSPoint)topLeftPoint
{ {
// FIXME: As we know nothing about the other window we can only guess NSRect cRect;
topLeftPoint.x += 20;
topLeftPoint.y += 20;
if (NSEqualPoints(topLeftPoint, NSZeroPoint) == YES)
{
topLeftPoint.x = _frame.origin.x;
topLeftPoint.y = _frame.origin.y + _frame.size.height;
}
[self setFrameTopLeftPoint: topLeftPoint]; [self setFrameTopLeftPoint: topLeftPoint];
cRect = [isa contentRectForFrameRect: _frame styleMask: _styleMask];
topLeftPoint.x = cRect.origin.x;
topLeftPoint.y = cRect.origin.y + cRect.size.height;
return topLeftPoint; return topLeftPoint;
} }
@ -4061,7 +4045,7 @@ resetCursorRectsForView(NSView *theView)
[_wv convertRect: rect fromView: nil]]; [_wv convertRect: rect fromView: nil]];
} }
- (NSData *)dataWithPDFInsideRect:(NSRect)aRect - (NSData *) dataWithPDFInsideRect:(NSRect)aRect
{ {
return [_wv dataWithPDFInsideRect: return [_wv dataWithPDFInsideRect:
[_wv convertRect: aRect fromView: nil]]; [_wv convertRect: aRect fromView: nil]];