Handle flipped views

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@3709 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1999-02-15 12:50:49 +00:00
parent 3d0220da1f
commit d0d0502814
5 changed files with 319 additions and 36 deletions

View file

@ -1,3 +1,10 @@
Mon Feb 15 12:20:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/NSBrowserCell.m: Code by Benhur to handle flipped views
* Source/NSButtonCell.m: ditto
* Source/NSCell.m: ditto
* Source/NSScrollView.m: ditto
1999-02-13 Michael Hanni <mhanni@sprintmail.com>
* Small change to gui/Tools/GNUmakefile.preamble to allow for easy

View file

@ -256,7 +256,7 @@ NSImage *image = nil;
[_browserText drawWithFrame:title_rect inView: controlView];
if (image) // Draw the image
[self _displayImage:image inFrame:image_rect];
[self _drawImage:image inFrame:image_rect];
}
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView

View file

@ -42,6 +42,7 @@
#include <AppKit/NSApplication.h>
#include <AppKit/NSFont.h>
#include <AppKit/NSImage.h>
#include <AppKit/NSColor.h>
@ -121,10 +122,11 @@
- (void)setAlternateTitle:(NSString *)aString
{
NSString* _string = [aString copy];
NSString* _string = [aString copy];
ASSIGN(altContents, _string);
[self setState:[self state]]; // update our state
ASSIGN(altContents, _string);
[_string release];
[self setState:[self state]]; // update our state
}
//
@ -300,11 +302,174 @@ NSString* _string = [aString copy];
//
// Displaying
//
- (NSColor *)textColor
{
if (([self state] && ([self showsStateBy] & NSChangeGrayCellMask))
|| ([self isHighlighted] && ([self highlightsBy] & NSChangeGrayCellMask)))
return [NSColor lightGrayColor];
return [NSColor blackColor];
}
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
control_view = controlView; // Save last view cell was drawn to
float backgroundGray = NSLightGray;
// do nothing if cell's frame rect is zero
if (NSIsEmptyRect(cellFrame))
return;
PSgsave ();
//fprintf(stderr,"XRButtonCell drawWithFrame \n");
// Save last view drawn to
[self setControlView: controlView];
// determine the background color
if ([self state])
{
if ( [self showsStateBy]
& (NSChangeGrayCellMask | NSChangeBackgroundCellMask) )
backgroundGray = NSWhite;
}
if ([self isHighlighted])
{
if ( [self highlightsBy]
& (NSChangeGrayCellMask | NSChangeBackgroundCellMask) )
backgroundGray = NSWhite;
}
// set cell's background color
[[NSColor colorWithCalibratedWhite:backgroundGray alpha:1.0] set];
NSRectFill(cellFrame);
// draw the border if needed
if ([self isBordered])
{
if ([self isHighlighted] && ([self highlightsBy] & NSPushInCellMask))
{
NSDrawGrayBezel (cellFrame, cellFrame);
cellFrame = NSInsetRect (cellFrame, 2, 2);
}
else
{
NSDrawButton (cellFrame, cellFrame);
cellFrame = NSInsetRect (cellFrame, 2, 2);
}
}
// NSRectClip (cellFrame);
[self drawInteriorWithFrame: cellFrame inView: controlView];
PSgrestore ();
}
- (void)drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView *)controlView
{
BOOL showAlternate = NO;
unsigned int mask;
NSImage *imageToDisplay;
NSString *titleToDisplay;
NSSize imageSize = {0, 0};
NSRect rect;
cellFrame = NSInsetRect (cellFrame, xDist, yDist);
// Determine the image and the title that will be
// displayed. If the NSContentsCellMask is set the
// image and title are swapped only if state is 1 or
// if highlighting is set (when a button is pushed it's
// content is changed to the face of reversed state).
if ([self isHighlighted])
mask = [self highlightsBy];
else
mask = [self showsStateBy];
if (mask & NSContentsCellMask)
showAlternate = [self state];
if (showAlternate || [self isHighlighted])
{
imageToDisplay = [self alternateImage];
titleToDisplay = [self alternateTitle];
if (!titleToDisplay)
titleToDisplay = [self title];
}
else
{
imageToDisplay = [self image];
titleToDisplay = [self title];
}
if (imageToDisplay)
imageSize = [imageToDisplay size];
rect = NSMakeRect (cellFrame.origin.x, cellFrame.origin.y,
imageSize.width, imageSize.height);
switch ([self imagePosition])
{
case NSNoImage:
// draw title only
[self _drawText: titleToDisplay inFrame: cellFrame];
break;
case NSImageOnly:
// draw image only
[self _drawImage: imageToDisplay inFrame: cellFrame];
break;
case NSImageLeft:
// draw image to the left of the title
rect.origin = cellFrame.origin;
rect.size.width = imageSize.width;
rect.size.height = cellFrame.size.height;
[self _drawImage: imageToDisplay inFrame: rect];
// draw title
rect.origin.x += imageSize.width + xDist;
rect.size.width = cellFrame.size.width - imageSize.width - xDist;
[self _drawText: titleToDisplay inFrame: rect];
break;
case NSImageRight:
// draw image to the right of the title
rect.origin.x = NSMaxX (cellFrame) - imageSize.width;
rect.origin.y = cellFrame.origin.y;
rect.size.width = imageSize.width;
rect.size.height = cellFrame.size.height;
[self _drawImage:imageToDisplay inFrame:rect];
// draw title
rect.origin = cellFrame.origin;
rect.size.width = cellFrame.size.width - imageSize.width - xDist;
rect.size.height = cellFrame.size.height;
[self _drawText: titleToDisplay inFrame: rect];
break;
case NSImageBelow:
// draw image below title
cellFrame.size.height /= 2;
[self _drawImage: imageToDisplay inFrame: cellFrame];
cellFrame.origin.y += cellFrame.size.height;
[self _drawText: titleToDisplay inFrame: cellFrame];
break;
case NSImageAbove:
// draw image above title
cellFrame.size.height /= 2;
[self _drawText: titleToDisplay inFrame: cellFrame];
cellFrame.origin.y += cellFrame.size.height;
[self _drawImage: imageToDisplay inFrame: cellFrame];
break;
case NSImageOverlaps:
// draw title over the image
[self _drawImage: imageToDisplay inFrame: cellFrame];
[self _drawText: titleToDisplay inFrame: cellFrame];
break;
}
}
- (id)copyWithZone:(NSZone*)zone
{
NSButtonCell* c = [super copyWithZone:zone];

View file

@ -41,6 +41,7 @@
#include <AppKit/NSControl.h>
#include <AppKit/NSCell.h>
#include <AppKit/NSEvent.h>
#include <AppKit/NSColor.h>
@ -236,14 +237,14 @@ NSString* number_string = [[NSNumber numberWithInt:anInt] stringValue];
- (void)setStringValue:(NSString *)aString
{
NSString* _string;
NSString* _string;
if (!aString)
_string = @"";
else
_string = [aString copy];
if (!aString)
_string = @"";
else
_string = [[aString copy] autorelease];
ASSIGN(contents, _string);
ASSIGN(contents, _string);
}
//
@ -414,36 +415,135 @@ NSString* _string;
- (NSView *)controlView { return control_view; }
- (void)setControlView:(NSView*)view { control_view = view; }
- (NSColor *)textColor
{
if ([self isEnabled])
return [NSColor blackColor];
else
return [NSColor darkGrayColor];
}
- (void) _drawText: (NSString *) title inFrame: (NSRect) cellFrame
{
NSColor *textColor;
NSFont *font;
float titleWidth;
float titleHeight;
if (!title)
return;
textColor = [self textColor];
font = [self font];
if (!font)
[NSException raise:NSInvalidArgumentException
format:@"Request to draw a text cell but no font specified!"];
titleWidth = [font widthOfString: title];
titleHeight = [font pointSize];
// Determine the y position of the text
cellFrame.origin.y = NSMidY (cellFrame) - titleHeight / 2;
cellFrame.size.height = titleHeight;
// Determine the x position of text
switch ([self alignment])
{
// ignore the justified and natural alignments
case NSLeftTextAlignment:
case NSJustifiedTextAlignment:
case NSNaturalTextAlignment:
break;
case NSRightTextAlignment:
if (titleWidth < NSWidth (cellFrame))
{
float shift = NSWidth (cellFrame) - titleWidth;
cellFrame.origin.x += shift;
cellFrame.size.width -= shift;
}
break;
case NSCenterTextAlignment:
if (titleWidth < NSWidth (cellFrame))
{
float shift = (NSWidth (cellFrame) - titleWidth) / 2;
cellFrame.origin.x += shift;
cellFrame.size.width -= shift;
}
}
[font set];
[textColor set];
[title drawInRect:cellFrame withAttributes: nil];
}
// Draw image centered in frame.
- (void) _drawImage: (NSImage *) image inFrame: (NSRect) cellFrame
{
NSSize size;
NSPoint position;
if (!image)
return;
size = [image size];
position.x = NSMidX (cellFrame) - size.width / 2;
position.y = NSMidY (cellFrame) - size.height / 2;
[image compositeToPoint: position operation: NSCompositeCopy];
}
- (void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
{
cellFrame = NSInsetRect (cellFrame, xDist, yDist);
switch ([self type])
{
case NSTextCellType:
{
NSText *fieldEditor;
fieldEditor = [[controlView window] fieldEditor: YES forObject: self];
[fieldEditor setString: [self stringValue]];
[fieldEditor setAlignment: [self alignment]];
[fieldEditor setFont: [self font]];
[fieldEditor setDrawsBackground: NO];
if ([self isEnabled])
[fieldEditor setTextColor: [NSColor blackColor]];
else
[fieldEditor setTextColor: [NSColor darkGrayColor]];
[fieldEditor setFrame: cellFrame];
[controlView addSubview: fieldEditor];
break;
}
[self _drawText: [self stringValue] inFrame: cellFrame];
break;
case NSImageCellType:
[self _displayImage:cell_image inFrame:cellFrame];
break;
[self _drawImage: [self image] inFrame: cellFrame];
break;
case NSNullCellType:
break;
}
}
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{ // implemented in back end
- (void)drawWithFrame: (NSRect)cellFrame inView: (NSView *)controlView
{
NSDebugLog (@"NSCell drawWithFrame:inView:");
// We apply a clipping rectangle so save the graphics state
PSgsave ();
// Save last view drawn to
[self setControlView: controlView];
// Clear the cell frame
if ([self isOpaque])
{
[[NSColor lightGrayColor] set];
NSRectFill(cellFrame);
}
// draw the border if needed
if ([self isBordered])
{
if ([self isBezeled])
{
NSDrawWhiteBezel (cellFrame, cellFrame);
cellFrame = NSInsetRect (cellFrame, 2, 2);
}
else
{
NSFrameRect (cellFrame);
cellFrame = NSInsetRect (cellFrame, 1, 1);
}
}
NSRectClip (cellFrame);
[self drawInteriorWithFrame: cellFrame inView: controlView];
PSgrestore ();
}
- (BOOL)isHighlighted { return cell_highlighted; }
@ -794,8 +894,19 @@ NSCell* c = [[isa allocWithZone: zone] init];
@implementation NSCell (GNUstepBackend)
+ (NSSize)sizeForBorderType:(NSBorderType)aType
{ // Returns the size of a
return NSZeroSize; // border
{
// Returns the size of a border
switch (aType)
{
case NSLineBorder:
return NSMakeSize(1, 1);
case NSGrooveBorder:
case NSBezelBorder:
return NSMakeSize(2, 2);
case NSNoBorder:
default:
return NSZeroSize;
}
}
@end

View file

@ -510,10 +510,10 @@ static Class rulerViewClass = nil;
float horizLinePosition, horizLineLength = [self bounds].size.width;
float borderThickness = 0;
fprintf (stderr,
"NSScrollView drawRect: origin (%1.2f, %1.2f), size (%1.2f, %1.2f)\n",
rect.origin.x, rect.origin.y,
rect.size.width, rect.size.height);
// fprintf (stderr,
// "NSScrollView drawRect: origin (%1.2f, %1.2f), size (%1.2f, %1.2f)\n",
// rect.origin.x, rect.origin.y,
// rect.size.width, rect.size.height);
PSgsave ();
switch ([self borderType])