Implement gstates in Windows and Views

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@4414 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Adam Fedor 1999-06-16 21:55:23 +00:00
parent f5b2653492
commit f794f819cf
12 changed files with 302 additions and 71 deletions

View file

@ -1,3 +1,24 @@
1999-06-16 Adam Fedor <fedor@gnu.org>
* Headers/gnustep/gui/DPSOperators.h: New functions
defineuserobject, execuserobject, and undefineuserobject for
dealing with gstates.
* Headers/gnustep/gui/GSMethodTable.h: Likewise.
* Headers/gnustep/gui/NSGraphicsContext.h. Likewise.
* Headers/gnustep/gui/PSOperators.h: Likewise.
* Headers/gnustep/gui/GSWraps.h: Wrapper functions for PostScript
functionality.
* Source/NSAffineTransform.m (-concat): Implement.
(-set): Likewise.
* Headers/gnustep/gui/NSView.h: New gstate ivars.
* Source/NSGraphicsContext.m: Move lockFocus code to NSView.
* Source/NSView.m (-lockFocusInRect:): New method implementing
proper gstate support.
(-lockFocus): Use it.
(-unlockFocusNeedsFlush): New method.
Wed Jun 16 22:15:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Images/common_Home.tiff: new file for save panel

View file

@ -381,6 +381,18 @@ __attribute__((unused));
/* ----------------------------------------------------------------------- */
/* Opstack operations */
/* ----------------------------------------------------------------------- */
static inline void
DPSdefineuserobject(GSCTXT *ctxt)
__attribute__((unused));
static inline void
DPSexecuserobject(GSCTXT *ctxt, int index)
__attribute__((unused));
static inline void
DPSundefineuserobject(GSCTXT *ctxt, int index)
__attribute__((unused));
static inline void
DPSgetboolean(GSCTXT *ctxt, int *it)
__attribute__((unused));
@ -1319,6 +1331,27 @@ DPStransform(GSCTXT *ctxt, float x1, float y1, float *x2, float *y2)
/* ----------------------------------------------------------------------- */
/* Opstack operations */
/* ----------------------------------------------------------------------- */
static inline void
DPSdefineuserobject(GSCTXT *ctxt)
{
(ctxt->methods->DPSdefineuserobject)
(ctxt, @selector(DPSdefineuserobject));
}
static inline void
DPSexecuserobject(GSCTXT *ctxt, int index)
{
(ctxt->methods->DPSexecuserobject_)
(ctxt, @selector(DPSexecuserobject), index);
}
static inline void
DPSundefineuserobject(GSCTXT *ctxt, int index)
{
(ctxt->methods->DPSundefineuserobject_)
(ctxt, @selector(DPSundefineuserobject:), index);
}
static inline void
DPSgetboolean(GSCTXT *ctxt, int *it)
{

View file

@ -220,6 +220,12 @@ typedef struct {
/* ----------------------------------------------------------------------- */
/* Opstack operations */
/* ----------------------------------------------------------------------- */
void (*DPSdefineuserobject)
(NSGraphicsContext*, SEL);
void (*DPSexecuserobject_)
(NSGraphicsContext*, SEL, int);
void (*DPSundefineuserobject_)
(NSGraphicsContext*, SEL, int);
void (*DPSgetboolean_)
(NSGraphicsContext*, SEL, int*);
void (*DPSgetchararray__)

View file

@ -0,0 +1,37 @@
/* GSWraps.h - Definitions of PostScript wraps for NSGraphicsContext
Copyright (C) 1999 Free Software Foundation, Inc.
Written by: Adam Fedor <fedor@gnu.org>
This file is part of the GNU Objective C User Interface library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
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., 675 Mass Ave, Cambrvoidge, MA 02139, USA.
*/
#ifndef _GSWraps_h_INCLUDE
#define _GSWraps_h_INCLUDE
#include <AppKit/NSGraphicsContext.h>
#define GSCTXT NSGraphicsContext
/* Graphics Wraps */
extern void GSWSetMatrix(GSCTXT *ctxt, float m[6]);
/* Context helper wraps */
extern unsigned int GSWDefineAsUserObj(GSCTXT *ctxt);
extern void GSWViewIsFlipped(GSCTXT *ctxt, BOOL flipped);
#endif

View file

@ -256,6 +256,9 @@ NSGraphicsContext *GSCurrentContext();
/* ----------------------------------------------------------------------- */
/* Opstack operations */
/* ----------------------------------------------------------------------- */
- (void) DPSdefineuserobject;
- (void) DPSexecuserobject: (int)index ;
- (void) DPSundefineuserobject: (int)index ;
- (void) DPSgetboolean: (int *)it ;
- (void) DPSgetchararray: (int)size : (char *)s ;
- (void) DPSgetfloat: (float*)it ;

View file

@ -87,6 +87,7 @@ enum {
NSRect invalidRect;
NSRect visibleRect;
unsigned int autoresizingMask;
int gstate;
BOOL is_rotated_from_base;
BOOL is_rotated_or_scaled_from_base;
@ -96,6 +97,8 @@ enum {
BOOL post_bounds_changes;
BOOL autoresize_subviews;
BOOL coordinates_valid;
BOOL allocate_gstate;
BOOL renew_gstate;
// Reserved for back-end use
void *be_view_reserved;

View file

@ -385,6 +385,18 @@ __attribute__((unused));
/* ----------------------------------------------------------------------- */
/* Opstack operations */
/* ----------------------------------------------------------------------- */
static inline void
PSdefineuserobject()
__attribute__((unused));
static inline void
PSexecuserobject(int index)
__attribute__((unused));
static inline void
PSundefineuserobject(int index)
__attribute__((unused));
static inline void
PSgetboolean(int *it)
__attribute__((unused));
@ -1241,6 +1253,24 @@ PStransform(float x1, float y1, float *x2, float *y2)
/* ----------------------------------------------------------------------- */
/* Opstack operations */
/* ----------------------------------------------------------------------- */
static inline void
PSdefineuserobject()
{
DPSdefineuserobject(DEFCTXT);
}
static inline void
PSexecuserobject(int index)
{
DPSexecuserobject(DEFCTXT, index);
}
static inline void
PSundefineuserobject(int index)
{
DPSundefineuserobject(DEFCTXT, index);
}
static inline void
PSgetboolean(int *it)
{

View file

@ -101,8 +101,14 @@ static NSAffineTransformStruct identityTransform = {
- (void) concat
{
// PSconcat(self);
[self subclassResponsibility: _cmd];
float m[6];
m[0] = matrix.m11;
m[1] = matrix.m12;
m[2] = matrix.m21;
m[3] = matrix.m22;
m[4] = matrix.tx;
m[5] = matrix.ty;
PSconcat(m);
}
- (id) init
@ -240,8 +246,14 @@ static NSAffineTransformStruct identityTransform = {
- (void) set
{
// PSsetmatrix(self);
[self subclassResponsibility: _cmd];
float m[6];
m[0] = matrix.m11;
m[1] = matrix.m12;
m[2] = matrix.m21;
m[3] = matrix.m22;
m[4] = matrix.tx;
m[5] = matrix.ty;
PSsetmatrix(m);
}
- (void) setTransformStruct: (NSAffineTransformStruct)val

View file

@ -84,11 +84,6 @@ NSGraphicsContext *GSCurrentContext()
+ (gsMethodTable *) _initializeMethodTable;
@end
struct NSWindow_struct
{
@defs(NSWindow)
};
@implementation NSGraphicsContext
+ (void) initialize
@ -236,33 +231,11 @@ struct NSWindow_struct
- (void) lockFocusView: (NSView*)aView inRect: (NSRect)rect
{
struct NSWindow_struct *window;
[focus_stack addObject: aView];
window = (struct NSWindow_struct *)[aView window];
/* Add aView's visible Rect to its Window's area to be flushed */
if (NSIsEmptyRect(rect))
rect = [aView visibleRect];
rect = [aView convertRect: rect toView: nil];
[window->rectsBeingDrawn addObject: [NSValue valueWithRect: rect]];
}
- (void) unlockFocusView: (NSView*)aView needsFlush: (BOOL)flush
{
NSRect rect;
struct NSWindow_struct *window;
NSView *v = [focus_stack lastObject];
NSAssert(v == aView, NSInvalidArgumentException);
/* Set Window's flush rect so our view is properly flushed */
window = (struct NSWindow_struct *)[aView window];
if (flush)
{
rect = [[window->rectsBeingDrawn lastObject] rectValue];
window->rectNeedingFlush = NSUnionRect(window->rectNeedingFlush, rect);
window->needs_flush = YES;
}
[window->rectsBeingDrawn removeLastObject];
[focus_stack removeLastObject];
}
@ -551,6 +524,12 @@ struct NSWindow_struct
/* ----------------------------------------------------------------------- */
/* Opstack operations */
/* ----------------------------------------------------------------------- */
methodTable.DPSdefineuserobject =
GET_IMP(@selector(DPSdefineuserobject));
methodTable.DPSexecuserobject_ =
GET_IMP(@selector(DPSexecuserobject:));
methodTable.DPSundefineuserobject_ =
GET_IMP(@selector(DPSundefineuserobject:));
methodTable.DPSgetboolean_ =
GET_IMP(@selector(DPSgetboolean:));
methodTable.DPSgetchararray__ =
@ -1204,6 +1183,21 @@ struct NSWindow_struct
/* Opstack operations */
/* ----------------------------------------------------------------------- */
- (void)DPSdefineuserobject
{
[self subclassResponsibility: _cmd];
}
- (void)DPSexecuserobject: (int)index
{
[self subclassResponsibility: _cmd];
}
- (void)DPSundefineuserobject: (int)index
{
[self subclassResponsibility: _cmd];
}
- (void) DPSgetboolean: (int *)it
{
[self subclassResponsibility: _cmd];

View file

@ -89,7 +89,7 @@ static NSOpenPanel *gnustep_gui_open_panel = nil;
{
NSDebugLLog(@"NSOpenPanel", @"NSOpenPanel +allocWithZone");
if( !gnustep_gui_open_panel)
gnustep_gui_open_panel = NSAllocateObject(self, 0, z);
gnustep_gui_open_panel = (NSOpenPanel *)NSAllocateObject(self, 0, z);
return gnustep_gui_open_panel;
}
@ -117,7 +117,7 @@ static NSOpenPanel *gnustep_gui_open_panel = nil;
- (void) setAllowsMultipleSelection: (BOOL)flag
{
allowsMultipleSelection=flag;
[browser setAllowsMultipleSelection: flag];
[_browser setAllowsMultipleSelection: flag];
}
- (BOOL) allowsMultipleSelection
@ -147,7 +147,7 @@ static NSOpenPanel *gnustep_gui_open_panel = nil;
- (NSString*) filename
{
return [browser path];
return [_browser path];
}
/*
@ -159,13 +159,13 @@ static NSOpenPanel *gnustep_gui_open_panel = nil;
return [NSArray arrayWithObject: [self filename]];
else
{
NSArray *cells=[browser selectedCells];
NSArray *cells=[_browser selectedCells];
NSEnumerator *cellEnum;
id currCell;
NSMutableArray *ret = [NSMutableArray array];
NSString *dir=[self directory];
for(cellEnum=[cells objectEnumerator];currCell=[cellEnum nextObject];)
for(cellEnum=[cells objectEnumerator];(currCell=[cellEnum nextObject]);)
{
[ret addObject: [NSString
stringWithFormat: @"%@/%@",dir,[currCell stringValue]]];
@ -189,9 +189,9 @@ static NSOpenPanel *gnustep_gui_open_panel = nil;
file: (NSString *)name
types: (NSArray *)fileTypes
{
if (requiredTypes)
[requiredTypes autorelease];
requiredTypes = [fileTypes retain];
if (_requiredFileType)
[_requiredFileType autorelease];
_requiredFileType = [fileTypes retain];
return [self runModalForDirectory: path file: name];
}
@ -228,7 +228,7 @@ static NSOpenPanel *gnustep_gui_open_panel = nil;
while (sp != NULL)
{
*sp = '\0';
m = [NSMutableString stringWithCString: files];
m = (NSMutableString *)[NSMutableString stringWithCString: files];
[m appendString: @"\\"];
[m appendString: [NSString stringWithCString: p]];
[the_filenames addObject: m];
@ -237,7 +237,7 @@ static NSOpenPanel *gnustep_gui_open_panel = nil;
}
if (strchr(p, '\0'))
{
m = [NSMutableString stringWithCString: files];
m = (NSMutableString *)[NSMutableString stringWithCString: files];
[m appendString: @"\\"];
[m appendString: [NSString stringWithCString: p]];
[the_filenames addObject: m];

View file

@ -48,8 +48,14 @@
#include <AppKit/NSView.h>
#include <AppKit/NSWindow.h>
#include <AppKit/GSTrackingRect.h>
#include <AppKit/GSWraps.h>
#include <AppKit/PSOperators.h>
#include <AppKit/NSAffineTransform.h>
struct NSWindow_struct
{
@defs(NSWindow)
};
@implementation NSView
@ -226,6 +232,7 @@ GSSetDragTypes(NSView* obj, NSArray *types)
TEST_RELEASE(tracking_rects);
TEST_RELEASE(cursor_rects);
[self unregisterDraggedTypes];
[self releaseGState];
[super dealloc];
}
@ -1148,36 +1155,135 @@ GSSetDragTypes(NSView* obj, NSArray *types)
- (void) allocateGState
{
// implemented by the back end
allocate_gstate = 1;
renew_gstate = 1;
}
- (void) releaseGState
{
// implemented by the back end
if (allocate_gstate && gstate)
PSundefineuserobject(gstate);
gstate = 0;
allocate_gstate = 0;
}
- (int) gState
{
return 0;
return gstate;
}
- (void) renewGState
{
renew_gstate = 1;
}
/* Overridden by subclasses to setup custom gstate */
- (void) setUpGState
{
}
- (void) lockFocusInRect: (NSRect)rect
{
NSGraphicsContext *ctxt = GSCurrentContext();
struct NSWindow_struct *window_t;
NSRect wrect;
[ctxt lockFocusView: self inRect: rect];
wrect = [self convertRect: rect toView: nil];
window_t = (struct NSWindow_struct *)window;
[window_t->rectsBeingDrawn addObject: [NSValue valueWithRect: wrect]];
DPSgsave(ctxt);
if (gstate)
{
DPSsetgstate(ctxt, gstate);
if (renew_gstate)
[self setUpGState];
renew_gstate = 0;
DPSgsave(ctxt);
}
else
{
int window_gstate;
NSAffineTransform *matrix;
float x, y, w, h;
window_gstate = [window gState];
NSAssert(window_gstate, NSInternalInconsistencyException);
DPSsetgstate(ctxt, window_gstate);
DPSgsave(ctxt);
matrix = [self _matrixToWindow];
[matrix concat];
/*
* Clipping - set viewclip to the visible rectangle - which will never be
* greater than the bounds of the view.
* Set the standard clippath to an empty path.
*/
if ([matrix isRotated])
[matrix boundingRectFor: rect result: &rect];
x = NSMinX(rect);
y = NSMinY(rect);
w = NSWidth(rect);
h = NSHeight(rect);
DPSrectviewclip(ctxt, x, y, w, h);
/* Allow subclases to make other modifications */
[self setUpGState];
renew_gstate = 0;
if (allocate_gstate)
{
DPSgstate(ctxt);
gstate = GSWDefineAsUserObj(ctxt);
/* Balance the previous gsave and install our own gstate */
DPSgrestore(ctxt);
DPSsetgstate(ctxt, gstate);
DPSgsave(ctxt);
}
else
{
/* This is just temporary so subclasses have a gstate to do
composite/disolve operations with */
gstate = window_gstate;
}
}
GSWViewIsFlipped(ctxt, _rFlags.flipped_view);
}
- (void) unlockFocusNeedsFlush: (BOOL)flush
{
NSRect rect;
struct NSWindow_struct *window_t;
NSGraphicsContext *ctxt = GSCurrentContext();
/* Restore our original gstate */
DPSgrestore(ctxt);
/* Restore gstate of nesting lockFocus (if any) */
DPSgrestore(ctxt);
if (!allocate_gstate)
gstate = 0;
window_t = (struct NSWindow_struct *)window;
if (flush)
{
rect = [[window_t->rectsBeingDrawn lastObject] rectValue];
window_t->rectNeedingFlush =
NSUnionRect(window_t->rectNeedingFlush, rect);
window_t->needs_flush = YES;
}
[window_t->rectsBeingDrawn removeLastObject];
[ctxt unlockFocusView: self needsFlush: YES ];
}
- (void) lockFocus
{
[GSCurrentContext() lockFocusView: self
inRect: [self visibleRect]];
[self lockFocusInRect: [self visibleRect]];
}
- (void) unlockFocus
{
[GSCurrentContext() unlockFocusView: self needsFlush: YES ];
[self unlockFocusNeedsFlush: YES ];
}
- (BOOL) canDraw
@ -1291,11 +1397,9 @@ GSSetDragTypes(NSView* obj, NSArray *types)
if (NSIsEmptyRect(redrawRect) == NO)
{
NSGraphicsContext *ctxt = GSCurrentContext();
[ctxt lockFocusView: self inRect: redrawRect];
[self lockFocusInRect: redrawRect];
[self drawRect: redrawRect];
[ctxt unlockFocusView: self needsFlush: YES];
[self unlockFocusNeedsFlush: YES];
}
if (_rFlags.has_subviews)
@ -1397,14 +1501,12 @@ GSSetDragTypes(NSView* obj, NSArray *types)
if (NSIsEmptyRect(aRect) == NO)
{
NSGraphicsContext *ctxt = GSCurrentContext();
/*
* Now we draw this view.
*/
[ctxt lockFocusView: self inRect: aRect];
[self lockFocusInRect: aRect];
[self drawRect: aRect];
[ctxt unlockFocusView: self needsFlush: YES];
[self unlockFocusNeedsFlush: YES];
}
if (_rFlags.has_subviews)

View file

@ -24,8 +24,10 @@
#include <Foundation/NSObject.h>
#include <Foundation/NSGeometry.h>
#include <AppKit/NSGraphics.h>
#include <AppKit/NSGraphicsContext.h>
#include <AppKit/NSCStringText.h>
#include <AppKit/NSEvent.h>
#include <AppKit/GSWraps.h>
/*
@ -70,22 +72,10 @@ void PSgrestore(void)
void PSgsave(void)
{}
void GSfill() {}
void GSsetgray() {}
void GSnewpath() {}
void GSgrestore() {}
void GSrectfill() {}
void GSsetlinewidth() {}
void GSclosepath() {}
void GSshow() {}
void GStranslate() {}
void GSmoveto() {}
void GSgsave() {}
void GSlineto() {}
void GSstroke() {}
void GSrlineto() {}
void GSrectclip() {}
/* Dummy wraps */
void GSWSetMatrix(GSCTXT *ctxt, float m[6]) {}
unsigned int GSWDefineAsUserObj(GSCTXT *ctxt) {return 0;}
void GSWViewIsFlipped(GSCTXT *ctxt, BOOL flipped) {}
@interface GMModel : NSObject
@end