mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-26 08:51:29 +00:00
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:
parent
3d0220da1f
commit
d0d0502814
5 changed files with 319 additions and 36 deletions
|
@ -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>
|
1999-02-13 Michael Hanni <mhanni@sprintmail.com>
|
||||||
|
|
||||||
* Small change to gui/Tools/GNUmakefile.preamble to allow for easy
|
* Small change to gui/Tools/GNUmakefile.preamble to allow for easy
|
||||||
|
|
|
@ -256,7 +256,7 @@ NSImage *image = nil;
|
||||||
[_browserText drawWithFrame:title_rect inView: controlView];
|
[_browserText drawWithFrame:title_rect inView: controlView];
|
||||||
|
|
||||||
if (image) // Draw the image
|
if (image) // Draw the image
|
||||||
[self _displayImage:image inFrame:image_rect];
|
[self _drawImage:image inFrame:image_rect];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
|
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
#include <AppKit/NSApplication.h>
|
#include <AppKit/NSApplication.h>
|
||||||
#include <AppKit/NSFont.h>
|
#include <AppKit/NSFont.h>
|
||||||
#include <AppKit/NSImage.h>
|
#include <AppKit/NSImage.h>
|
||||||
|
#include <AppKit/NSColor.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -121,9 +122,10 @@
|
||||||
|
|
||||||
- (void)setAlternateTitle:(NSString *)aString
|
- (void)setAlternateTitle:(NSString *)aString
|
||||||
{
|
{
|
||||||
NSString* _string = [aString copy];
|
NSString* _string = [aString copy];
|
||||||
|
|
||||||
ASSIGN(altContents, _string);
|
ASSIGN(altContents, _string);
|
||||||
|
[_string release];
|
||||||
[self setState:[self state]]; // update our state
|
[self setState:[self state]]; // update our state
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,11 +302,174 @@ NSString* _string = [aString copy];
|
||||||
//
|
//
|
||||||
// Displaying
|
// 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
|
- (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
|
- (id)copyWithZone:(NSZone*)zone
|
||||||
{
|
{
|
||||||
NSButtonCell* c = [super copyWithZone:zone];
|
NSButtonCell* c = [super copyWithZone:zone];
|
||||||
|
|
153
Source/NSCell.m
153
Source/NSCell.m
|
@ -41,6 +41,7 @@
|
||||||
#include <AppKit/NSControl.h>
|
#include <AppKit/NSControl.h>
|
||||||
#include <AppKit/NSCell.h>
|
#include <AppKit/NSCell.h>
|
||||||
#include <AppKit/NSEvent.h>
|
#include <AppKit/NSEvent.h>
|
||||||
|
#include <AppKit/NSColor.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -236,12 +237,12 @@ NSString* number_string = [[NSNumber numberWithInt:anInt] stringValue];
|
||||||
|
|
||||||
- (void)setStringValue:(NSString *)aString
|
- (void)setStringValue:(NSString *)aString
|
||||||
{
|
{
|
||||||
NSString* _string;
|
NSString* _string;
|
||||||
|
|
||||||
if (!aString)
|
if (!aString)
|
||||||
_string = @"";
|
_string = @"";
|
||||||
else
|
else
|
||||||
_string = [aString copy];
|
_string = [[aString copy] autorelease];
|
||||||
|
|
||||||
ASSIGN(contents, _string);
|
ASSIGN(contents, _string);
|
||||||
}
|
}
|
||||||
|
@ -414,36 +415,135 @@ NSString* _string;
|
||||||
- (NSView *)controlView { return control_view; }
|
- (NSView *)controlView { return control_view; }
|
||||||
- (void)setControlView:(NSView*)view { control_view = 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
|
- (void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
|
||||||
{
|
{
|
||||||
|
cellFrame = NSInsetRect (cellFrame, xDist, yDist);
|
||||||
|
|
||||||
switch ([self type])
|
switch ([self type])
|
||||||
{
|
{
|
||||||
case NSTextCellType:
|
case NSTextCellType:
|
||||||
{
|
[self _drawText: [self stringValue] inFrame: cellFrame];
|
||||||
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;
|
break;
|
||||||
}
|
|
||||||
case NSImageCellType:
|
case NSImageCellType:
|
||||||
[self _displayImage:cell_image inFrame:cellFrame];
|
[self _drawImage: [self image] inFrame: cellFrame];
|
||||||
break;
|
break;
|
||||||
case NSNullCellType:
|
case NSNullCellType:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
|
- (void)drawWithFrame: (NSRect)cellFrame inView: (NSView *)controlView
|
||||||
{ // implemented in back end
|
{
|
||||||
|
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; }
|
- (BOOL)isHighlighted { return cell_highlighted; }
|
||||||
|
@ -794,8 +894,19 @@ NSCell* c = [[isa allocWithZone: zone] init];
|
||||||
@implementation NSCell (GNUstepBackend)
|
@implementation NSCell (GNUstepBackend)
|
||||||
|
|
||||||
+ (NSSize)sizeForBorderType:(NSBorderType)aType
|
+ (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
|
@end
|
||||||
|
|
|
@ -510,10 +510,10 @@ static Class rulerViewClass = nil;
|
||||||
float horizLinePosition, horizLineLength = [self bounds].size.width;
|
float horizLinePosition, horizLineLength = [self bounds].size.width;
|
||||||
float borderThickness = 0;
|
float borderThickness = 0;
|
||||||
|
|
||||||
fprintf (stderr,
|
// fprintf (stderr,
|
||||||
"NSScrollView drawRect: origin (%1.2f, %1.2f), size (%1.2f, %1.2f)\n",
|
// "NSScrollView drawRect: origin (%1.2f, %1.2f), size (%1.2f, %1.2f)\n",
|
||||||
rect.origin.x, rect.origin.y,
|
// rect.origin.x, rect.origin.y,
|
||||||
rect.size.width, rect.size.height);
|
// rect.size.width, rect.size.height);
|
||||||
|
|
||||||
PSgsave ();
|
PSgsave ();
|
||||||
switch ([self borderType])
|
switch ([self borderType])
|
||||||
|
|
Loading…
Reference in a new issue