1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
/*
ZipperCell.m
Zipper
Copyright (C) 2012 Free Software Foundation, Inc
Authors: Dirk Olmes <dirk@xanthippe.ping.de>
Riccardo Mottola <rm@gnu.org>
This application is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your option)
any later version.
This program 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 General Public License for more details
*/
#import <AppKit/AppKit.h>
#import "ZipperCell.h"
@implementation ZipperCell : NSTextFieldCell
- (id) init
{
self = [super initTextCell: @""];
return self;
}
/*
* drawInteriorWithFrame is copied from NSCell.m and NSTextFieldCell.m
* and modified to to display an image _and_ text.
*/
- (void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
{
NSAttributedString *attStrVal;
if ([self drawsBackground])
{
[[self backgroundColor] set];
NSRectFill ([self drawingRectForBounds: cellFrame]);
}
if (![controlView window])
{
return;
}
cellFrame = [self drawingRectForBounds: cellFrame];
//FIXME: Check if this is also neccessary for images,
// Add spacing between border and inside
if ([self isBordered] || [self isBezeled])
{
cellFrame.origin.x += 3;
cellFrame.size.width -= 6;
cellFrame.origin.y += 1;
cellFrame.size.height -= 2;
}
if ([self image])
{
NSSize size;
NSPoint position;
size = [[self image] size];
position.x = 0.;
position.y = MAX(NSMidY(cellFrame) - (size.height/2.),0.);
/*
* Images are always drawn with their bottom-left corner
* at the origin so we must adjust the position to take
* account of a flipped view.
*/
if ([controlView isFlipped])
position.y += size.height;
[[self image] compositeToPoint: position operation: NSCompositeSourceOver];
cellFrame.origin.x += size.width+3;
cellFrame.size.width -= (size.width+3);
}
attStrVal = [self attributedStringValue];
if (attStrVal)
{
NSRect aRect;
NSSize stringSize;
stringSize = [attStrVal size];
aRect = cellFrame;
aRect.origin.y = NSMidY (aRect) - stringSize.height/2;
aRect.size.height = stringSize.height;
[attStrVal drawInRect: cellFrame];
}
if ([self showsFirstResponder])
{
NSDottedFrameRect(cellFrame);
}
}
@end
|