mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 15:11:37 +00:00
Window frame/coordinate handling cleanups
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@23460 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
17d346b3e5
commit
2eede887c5
6 changed files with 146 additions and 101 deletions
|
@ -1,3 +1,11 @@
|
|||
2006-09-12 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/GSWindowDecorationView.m: Simplify/rewrite to have the view
|
||||
always match the window frame so that the window base coordinate
|
||||
system has its origin at the bottom left corner of the window frame.
|
||||
* Headers/AppKit/NSWindow.h: Improve documentation
|
||||
* Headers/Additions/GNUstepGUI/GSDisplayServer.h: ditto
|
||||
|
||||
2006-09-06 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Headers/AppKit/NSWindow.h: Add some documentation about what
|
||||
|
|
|
@ -21,7 +21,8 @@
|
|||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#ifndef _GSDisplayServer_h_INCLUDE
|
||||
|
|
|
@ -101,30 +101,44 @@ typedef enum _NSSelectionDirection {
|
|||
APPKIT_EXPORT NSSize NSIconSize;
|
||||
APPKIT_EXPORT NSSize NSTokenSize;
|
||||
|
||||
/**
|
||||
* <p>An NSWindow instance represents a window, panel or menu on the
|
||||
* screen.<br />
|
||||
* Each window has a style, which determines how the window is decorated:
|
||||
* ie whether it has a border, a title bar, a resize bar, minimise and
|
||||
* close buttons.
|
||||
* </p>
|
||||
* <p>A window has a <em>frame</em>. This is the frame of the <em>entire</em>
|
||||
* window on the screen, including all decorations and borders. The origin
|
||||
* of the frame represents its bottom left corner and the frame is expressed
|
||||
* in screen coordinates (see [NSScreen]).<br />
|
||||
* </p>
|
||||
* <p>When a window is created, it has a <em>private</em> [NSView] instance
|
||||
* which fills the entire window frame and whose coordinate system is the
|
||||
* same as the base coordinate system of the window (ie zero x and
|
||||
* y coordinates are at the bottom left corner of the window, with increasing
|
||||
* x and y corresponding to points to the right and above the origin).<br />
|
||||
* This view may be used by the library internals (and theme engines) to
|
||||
* draw window decorations if the backend library is not handling the
|
||||
* window decorations.
|
||||
* </p>
|
||||
* <p>A window always contains a <em>content view<em> which is the highest
|
||||
* level view available for public (application) use. This view fills the
|
||||
* area of the window inside any decoration/border.<br />
|
||||
* This is the only part of the window that application programmers are
|
||||
* allowed to draw in directly.
|
||||
* </p>
|
||||
* <p>You can convert between view coordinates and window base coordinates
|
||||
* using the [NSView-convertPoint:fromView:], [NSView-convertPoint:toView:],
|
||||
* [NSView-convertRect:fromView:], and [NSView-convertRect:toView:]
|
||||
* methods with a nil view argument.<br />
|
||||
* You can convert between window and screen coordinates using the
|
||||
* -convertBaseToScreen: and -convertScreenToBase: methods.
|
||||
* </p>
|
||||
*/
|
||||
@interface NSWindow : NSResponder <NSCoding>
|
||||
{
|
||||
/*
|
||||
A window really has three interesting frames:
|
||||
|
||||
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).
|
||||
|
||||
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
|
||||
the frame of the area the gui library internals can draw into.
|
||||
|
||||
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, Frame >= BackendFrame >= ContentRect. When -gui doesn't
|
||||
manage the window decorations, BackendFrame == ContentRect. When -gui does
|
||||
manage the window decorations, BackendFrame will include the decorations,
|
||||
and Frame == BackendFrame.
|
||||
|
||||
*/
|
||||
NSRect _frame;
|
||||
|
||||
|
||||
NSSize _minimumSize;
|
||||
NSSize _maximumSize;
|
||||
NSSize _increments;
|
||||
|
@ -214,7 +228,8 @@ APPKIT_EXPORT NSSize NSTokenSize;
|
|||
/**
|
||||
* 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.
|
||||
* and which is decorated with the border and title etc given by aStyle.<br />
|
||||
* Both rectangles are expressed in screen coordinates.
|
||||
*/
|
||||
+ (NSRect) contentRectForFrameRect: (NSRect)aRect
|
||||
styleMask: (unsigned int)aStyle;
|
||||
|
@ -222,7 +237,8 @@ APPKIT_EXPORT NSSize NSTokenSize;
|
|||
/**
|
||||
* 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.
|
||||
* and was decorated with the border and title etc given by aStyle.<br />
|
||||
* Both rectangles are expressed in screen coordinates.
|
||||
*/
|
||||
+ (NSRect) frameRectForContentRect: (NSRect)aRect
|
||||
styleMask: (unsigned int)aStyle;
|
||||
|
@ -244,6 +260,12 @@ APPKIT_EXPORT NSSize NSTokenSize;
|
|||
backing: (NSBackingStoreType)bufferingType
|
||||
defer: (BOOL)flag;
|
||||
|
||||
/**
|
||||
* Creates a new window with the specified characteristics.<br />
|
||||
* The contentRect is expressed in screen coordinates (for aScreen)
|
||||
* and the window frame is calculated from the content rectangle and
|
||||
* the window style mask.
|
||||
*/
|
||||
- (id) initWithContentRect: (NSRect)contentRect
|
||||
styleMask: (unsigned int)aStyle
|
||||
backing: (NSBackingStoreType)bufferingType
|
||||
|
|
|
@ -21,7 +21,8 @@
|
|||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include <Foundation/NSArray.h>
|
||||
|
@ -278,7 +279,9 @@ GSCurrentServer(void)
|
|||
return nil;
|
||||
}
|
||||
|
||||
|
||||
/** Returns YES if the backend handles window decorations and NO
|
||||
* if the gui library must do that instead.
|
||||
*/
|
||||
- (BOOL) handlesWindowDecorations
|
||||
{
|
||||
return YES;
|
||||
|
@ -516,13 +519,15 @@ GSCurrentServer(void)
|
|||
|
||||
/** Creates a window whose location and size is described by frame and
|
||||
whose backing store is described by type. This window is not
|
||||
mapped to the screen by this call.
|
||||
mapped to the screen by this call.<br />
|
||||
|
||||
Note that frame is the frame of the drawable window and does not include
|
||||
any external window decorations. If handlesWindowDecorations returns YES,
|
||||
a window manager (or something equivalent) might add decorations outside
|
||||
the drawable window. Use -styleoffsets::::: to determine the extent of
|
||||
those decorations.
|
||||
Note that frame is the frame of the entire GNUstep window including
|
||||
borders, titlebar and other standard decorations.<br />
|
||||
If -handlesWindowDecorations returns YES, the backend will produce
|
||||
(and return the identifier of) a smaller drawable window inside this
|
||||
decorated area.<br />
|
||||
Use -styleoffsets::::: to determine the extent of the decorations
|
||||
and determine the size of the drawable area inside them.
|
||||
*/
|
||||
- (int) window: (NSRect)frame : (NSBackingStoreType)type : (unsigned int)style
|
||||
{
|
||||
|
@ -549,8 +554,11 @@ GSCurrentServer(void)
|
|||
|
||||
/** Create all the backend structures for a reference to a native window and
|
||||
return the extend, backing type, style and screen for that window. */
|
||||
- (int) nativeWindow: (void *)winref : (NSRect*)frame : (NSBackingStoreType*)type
|
||||
: (unsigned int*)style : (int*)screen
|
||||
- (int) nativeWindow: (void *)winref
|
||||
: (NSRect*)frame
|
||||
: (NSBackingStoreType*)type
|
||||
: (unsigned int*)style
|
||||
: (int*)screen
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
return 0;
|
||||
|
@ -612,19 +620,31 @@ GSCurrentServer(void)
|
|||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
/** Moves the bottom left cornder of the window to loc */
|
||||
/** Moves the bottom left corner of the window (including any border)
|
||||
* to loc.<br />
|
||||
* The position is expressed as an offset from the bottom left
|
||||
* corner of the screen.
|
||||
*/
|
||||
- (void) movewindow: (NSPoint)loc : (int) win
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
/** Moves and resizes the window on the screen as described by frame. */
|
||||
/** Moves and resizes the window on the screen as described by frame.
|
||||
* The value of frame is a rectangle containing the entire window, including
|
||||
* any border/decorations. Its position is expressed as an offset from
|
||||
* the bottom left corner of the screen.
|
||||
*/
|
||||
- (void) placewindow: (NSRect)frame : (int) win
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
/** Returns the frame of the window on the screen */
|
||||
/** Returns the frame of the window on the screen.<br />
|
||||
* The value of frame is a rectangle containing the entire window, including
|
||||
* any border/decorations. Its position is expressed as an offset from
|
||||
* the bottom left corner of the screen.
|
||||
*/
|
||||
- (NSRect) windowbounds: (int) win
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
|
@ -658,13 +678,13 @@ GSCurrentServer(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/** Set the maximum size of the window */
|
||||
/** Set the maximum size (pixels) of the window */
|
||||
- (void) setmaxsize: (NSSize)size : (int) win
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
/** Set the minimum size of the window */
|
||||
/** Set the minimum size (pixels) of the window */
|
||||
- (void) setminsize: (NSSize)size : (int) win
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
|
@ -676,18 +696,22 @@ GSCurrentServer(void)
|
|||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
/** Causes buffered graphics to be flushed to the screen */
|
||||
/** Causes buffered graphics to be flushed to the screen.
|
||||
* The value of rect is expressed in OpenStep window coordinates.
|
||||
*/
|
||||
- (void) flushwindowrect: (NSRect)rect : (int) win
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
/** Returns the dimensions of window decorations added outside the drawable
|
||||
window frame by a window manager or equivalent. For instance, t
|
||||
gives the height of the title bar for the window. The values returned
|
||||
may be approximations. If handlesWindowDecorations returns NO, there
|
||||
are no decorations outside the drawable window frame and this method
|
||||
shouldn't be called. */
|
||||
/**
|
||||
* Returns the dimensions of window decorations added outside the drawable
|
||||
* window frame by a window manager or equivalent. For instance, t
|
||||
* gives the height of the title bar for the window.<br />
|
||||
* If -handlesWindowDecorations returns NO, there
|
||||
* are no decorations outside the drawable window frame and this method
|
||||
* shouldn't be called.
|
||||
* */
|
||||
- (void) styleoffsets: (float*) l : (float*) r : (float*) t : (float*) b
|
||||
: (unsigned int) style
|
||||
{
|
||||
|
@ -722,8 +746,11 @@ GSCurrentServer(void)
|
|||
}
|
||||
|
||||
/** Returns the current mouse location on the default screen. If the
|
||||
pointer is not on the default screen, an invalid point (-1,-1} is
|
||||
returned. */
|
||||
* pointer is not on the default screen, an invalid point (-1,-1} is
|
||||
* returned.<br />
|
||||
* The location is expressed as an offset from the bottom left corner
|
||||
* of the screen.
|
||||
*/
|
||||
- (NSPoint) mouselocation
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
|
@ -731,10 +758,13 @@ GSCurrentServer(void)
|
|||
}
|
||||
|
||||
/** Returns the current mouse location on aScreen. If the pointer is
|
||||
not on aScreen, this method acts like -mouselocation. If aScreen is -1,
|
||||
then the location of the mouse on any screen is returned. The
|
||||
win pointer returns the window number of the GNUstep window
|
||||
that the mouse is in or 0 if it is not in a window. */
|
||||
* not on aScreen, this method acts like -mouselocation. If aScreen is -1,
|
||||
* then the location of the mouse on any screen is returned. The
|
||||
* win pointer returns the window number of the GNUstep window
|
||||
* that the mouse is in or 0 if it is not in a window.<br />
|
||||
* The location is expressed as an offset from the bottom left corner
|
||||
* of the screen.
|
||||
*/
|
||||
- (NSPoint) mouseLocationOnScreen: (int)aScreen window: (int *)win
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
|
@ -802,6 +832,16 @@ GSCurrentServer(void)
|
|||
/* GNUstep Event Operations */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
@implementation GSDisplayServer (EventOps)
|
||||
|
||||
/**
|
||||
* Scans through the event queue to find the first event whose type matches
|
||||
* mask. If no event is found, then the current run loop is run in the
|
||||
* specified mode to allow more events to arrive.<br />
|
||||
* If a matching event is found, it is returned and either removed from or
|
||||
* left in the queue according to flag.<br />
|
||||
* If no matching event is found and the limit date is reached, this method
|
||||
* returns nil.
|
||||
*/
|
||||
- (NSEvent*) getEventMatchingMask: (unsigned)mask
|
||||
beforeDate: (NSDate*)limit
|
||||
inMode: (NSString*)mode
|
||||
|
@ -853,7 +893,7 @@ GSCurrentServer(void)
|
|||
}
|
||||
|
||||
/*
|
||||
* Note the positon we have read up to.
|
||||
* Note the position we have read up to.
|
||||
*/
|
||||
pos += i;
|
||||
|
||||
|
@ -884,6 +924,11 @@ GSCurrentServer(void)
|
|||
return nil; /* No events in specified time */
|
||||
}
|
||||
|
||||
/**
|
||||
* Steps through the event queue and removes all events whose timestamp
|
||||
* is earlier than that of limit wand which match the supplied mask
|
||||
* of event types.
|
||||
*/
|
||||
- (void) discardEventsMatchingMask: (unsigned)mask
|
||||
beforeEvent: (NSEvent*)limit
|
||||
{
|
||||
|
@ -906,14 +951,20 @@ GSCurrentServer(void)
|
|||
|
||||
if ([event timestamp] < when)
|
||||
{
|
||||
if ((mask == NSAnyEventMask) ||
|
||||
(mask & NSEventMaskFromType([event type])))
|
||||
[event_queue removeObjectAtIndex: index];
|
||||
if ((mask == NSAnyEventMask)
|
||||
|| (mask & NSEventMaskFromType([event type])))
|
||||
{
|
||||
[event_queue removeObjectAtIndex: index];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Posts an event to the event queue. The value of flag determines
|
||||
* whether the event is inserted at the start of the queue or appended
|
||||
* at the end.
|
||||
*/
|
||||
- (void) postEvent: (NSEvent*)anEvent atStart: (BOOL)flag
|
||||
{
|
||||
if (flag)
|
||||
|
|
|
@ -104,20 +104,6 @@ struct NSWindow_struct
|
|||
}
|
||||
|
||||
|
||||
+ (NSRect) decorationRectForFrameRect: (NSRect)aRect
|
||||
styleMask: (unsigned int)aStyle
|
||||
{
|
||||
aRect.origin = NSZeroPoint;
|
||||
return aRect;
|
||||
}
|
||||
|
||||
+ (NSRect) contentRectForDecorationRect: (NSRect)aRect
|
||||
styleMask: (unsigned int)aStyle
|
||||
{
|
||||
return [self contentRectForFrameRect: aRect styleMask: aStyle];
|
||||
}
|
||||
|
||||
|
||||
- (id) initWithFrame: (NSRect)frame
|
||||
{
|
||||
NSAssert(NO, @"Tried to create GSWindowDecorationView without a window!");
|
||||
|
@ -127,15 +113,11 @@ struct NSWindow_struct
|
|||
- (id) initWithFrame: (NSRect)frame
|
||||
window: (NSWindow *)w
|
||||
{
|
||||
unsigned int styleMask = [w styleMask];
|
||||
|
||||
frame = [isa decorationRectForFrameRect: frame
|
||||
styleMask: styleMask];
|
||||
self = [super initWithFrame: frame];
|
||||
if (self != nil)
|
||||
{
|
||||
contentRect = [isa contentRectForDecorationRect: frame
|
||||
styleMask: styleMask];
|
||||
contentRect = [isa contentRectForFrameRect: frame
|
||||
styleMask: [w styleMask]];
|
||||
window = w;
|
||||
}
|
||||
return self;
|
||||
|
@ -176,14 +158,11 @@ struct NSWindow_struct
|
|||
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]];
|
||||
contentRect = [isa contentRectForFrameRect: frameRect
|
||||
styleMask: [window styleMask]];
|
||||
|
||||
// Safety Check.
|
||||
[cv setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
|
||||
|
@ -261,22 +240,5 @@ struct NSWindow_struct
|
|||
return 0.0;
|
||||
}
|
||||
|
||||
+ (NSRect) decorationRectForFrameRect: (NSRect)aRect
|
||||
styleMask: (unsigned int)aStyle
|
||||
{
|
||||
float l, r, t, b;
|
||||
|
||||
[self offsets: &l : &r : &t : &b forStyleMask: aStyle];
|
||||
aRect.size.width -= l + r;
|
||||
aRect.size.height -= t + b;
|
||||
return aRect;
|
||||
}
|
||||
|
||||
+ (NSRect) contentRectForDecorationRect: (NSRect)aRect
|
||||
styleMask: (unsigned int)aStyle
|
||||
{
|
||||
return aRect;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -23,7 +23,8 @@
|
|||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
|
||||
|
@ -295,12 +296,12 @@ NSGraphicsContext *GSCurrentContext(void)
|
|||
return context_info;
|
||||
}
|
||||
|
||||
- (void)flushGraphics
|
||||
- (void) flushGraphics
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
- (void *)graphicsPort
|
||||
- (void *) graphicsPort
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue