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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
|
/** <title>NSBrowserCell</title>
<abstract>Cell class for the NSBrowser</abstract>
Copyright (C) 1996, 1997, 1999 Free Software Foundation, Inc.
Author: Scott Christley <scottc@net-community.com>
Date: 1996
Author: Nicola Pero <n.pero@mi.flashnet.it>
Date: December 1999
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; see the file COPYING.LIB.
If not, see <http://www.gnu.org/licenses/> or write to the
Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#import "config.h"
#import <Foundation/NSUserDefaults.h>
#import "AppKit/NSBrowserCell.h"
#import "AppKit/NSColor.h"
#import "AppKit/NSFont.h"
#import "AppKit/NSImage.h"
#import "AppKit/NSGraphics.h"
#import "AppKit/NSEvent.h"
#import "AppKit/NSWindow.h"
#import "GSGuiPrivate.h"
#import "GNUstepGUI/GSTheme.h"
/*
* Class variables
*/
static Class _colorClass;
// GNUstep user default to have NSBrowserCell in bold if non leaf
static BOOL _gsFontifyCells = NO;
static NSFont *_nonLeafFont;
static NSFont *_leafFont;
/**<p> TODO Description</p>
*/
@implementation NSBrowserCell
/*
* Class methods
*/
+ (void) initialize
{
if (self == [NSBrowserCell class])
{
[self setVersion: 1];
/*
* Cache classes to avoid overheads of poor compiler implementation.
*/
_colorClass = [NSColor class];
// A GNUstep experimental feature
if ([[NSUserDefaults standardUserDefaults]
boolForKey: @"GSBrowserCellFontify"])
{
_gsFontifyCells = YES;
_nonLeafFont = RETAIN ([NSFont boldSystemFontOfSize: 0]);
_leafFont = RETAIN ([NSFont systemFontOfSize: 0]);
}
}
}
/**<p>Returns the default branch image. Currently, it's an arrow. </p>
*<p>See Also: +highlightedBranchImage </p>
*/
+ (NSImage*) branchImage
{
return [[GSTheme theme] branchImage];
}
/**<p>Returns the default hightlited branch image</p>
*<p>See Also: +branchImage</p>
*/
+ (NSImage*) highlightedBranchImage
{
return [[GSTheme theme] highlightedBranchImage];
}
/*
* Instance methods
*/
- (id) initTextCell: (NSString *)aString
{
self = [super initTextCell: aString];
if (nil == self)
return self;
//_alternateImage = nil;
//_browsercell_is_leaf = NO;
//_browsercell_is_loaded = NO;
[self setLineBreakMode: NSLineBreakByTruncatingTail];
if (_gsFontifyCells)
[self setFont: _nonLeafFont];
return self;
}
- (id) initImageCell: (NSImage *)anImage
{
self = [super initImageCell: anImage];
if (nil == self)
return self;
//_alternateImage = nil;
//_browsercell_is_leaf = NO;
//_browsercell_is_loaded = NO;
[self setLineBreakMode: NSLineBreakByTruncatingTail];
if (_gsFontifyCells)
[self setFont: _nonLeafFont];
return self;
}
- (void) dealloc
{
TEST_RELEASE (_alternateImage);
[super dealloc];
}
- (id) copyWithZone: (NSZone*)zone
{
NSBrowserCell *c = [super copyWithZone: zone];
_alternateImage = TEST_RETAIN (_alternateImage);
//c->_browsercell_is_leaf = _browsercell_is_leaf;
//c->_browsercell_is_loaded = _browsercell_is_loaded;
return c;
}
/**<p>Returns the alternate image in the NSBrowserCell
(used when the cell is highlighted) </p>
<p>See Also: -setAlternateImage:</p>
*/
- (NSImage*) alternateImage
{
return _alternateImage;
}
/**<p>Sets the altenate image (used when the cell is highlighted) to anImage
*</p><p>See Also: -alternateImage</p>
*/
- (void) setAlternateImage: (NSImage *)anImage
{
ASSIGN(_alternateImage, anImage);
}
- (NSImage*) image
{
/**
* NSCell implementation requires our type to be an image cell which
* is not desirable for NSBrowserCell. See also comment in setType:
*/
return _cell_image;
}
- (void) setImage: (NSImage*)anImage
{
/**
* NSCell implementation changes our type to an image cell which
* is not desirable for NSBrowserCell. See also comment in setType:
*/
ASSIGN (_cell_image, anImage);
}
- (NSColor *)highlightColorInView: (NSView *)controlView
{
return [_colorClass selectedControlColor];
}
/**<p>Returns whether the browserCell is a leaf. A leaf cell has usually no
* image. This method is used by NSBrowser in several methods, for example
* to know if a column should be added; when the user selects a browser cell
* (a branch or a leaf)</p>
* <p>See Also: -setLeaf: </p>
*/
- (BOOL) isLeaf
{
return _browsercell_is_leaf;
}
/**<p>Sets whether the cell is a leaf. This method is usally used in the
* NSBrowser's delegate methods</p>
*<p>See Also: -isLeaf</p>
*/
- (void) setLeaf: (BOOL)flag
{
if (_browsercell_is_leaf == flag)
return;
_browsercell_is_leaf = flag;
if (_gsFontifyCells)
{
if (_browsercell_is_leaf)
{
[self setFont: _leafFont];
}
else
{
[self setFont: _nonLeafFont];
}
}
}
/**<p>Returns whether the NSBrowseCell state is set and is ready for
display</p> <p>See Also: -setLoaded:</p>
*/
- (BOOL) isLoaded
{
return _browsercell_is_loaded;
}
/**<p>Sets whether the NSBrowseCell state is set and is ready for display</p>
* <p>See Also: -isLoaded </p>
*/
- (void) setLoaded: (BOOL)flag
{
_browsercell_is_loaded = flag;
}
/**
*<p>Unhighlights the cell and sets the cell's state to NO</p>
*<p>See Also: -set</p>
*/
- (void) reset
{
_cell.is_highlighted = NO;
_cell.state = NO;
}
/**<p>Highlights the cell and sets the cell's state to YES</p>
*<p>See Also: -reset</p>
*/
- (void) set
{
_cell.is_highlighted = YES;
_cell.state = YES;
}
- (void) setType: (NSCellType)aType
{
/* We do nothing here (we match the Mac OS X behavior) because with
* NSBrowserCell GNUstep implementation the cell may contain an image
* and text at the same time.
*/
}
- (NSRect) titleRectForBounds: (NSRect)theRect
{
NSRect titleRect = [super titleRectForBounds: theRect];
NSImage *branch_image = nil;
NSImage *cell_image = [self image];
if (_cell.is_highlighted || _cell.state)
{
if (!_browsercell_is_leaf)
{
branch_image = [object_getClass(self) highlightedBranchImage];
}
if (nil != [self alternateImage])
{
cell_image = [self alternateImage];
}
}
else
{
if (!_browsercell_is_leaf)
{
branch_image = [object_getClass(self) branchImage];
}
}
if (branch_image)
{
NSRect imgRect;
imgRect.size = [branch_image size];
titleRect.size.width -= imgRect.size.width + 8;
}
if (cell_image)
{
NSRect imgRect;
imgRect.size = [cell_image size];
titleRect.origin.x += imgRect.size.width + 4;
titleRect.size.width -= imgRect.size.width + 4;
}
// Skip 2 points from the left border
titleRect.origin.x += 2;
titleRect.size.width -= 2;
return titleRect;
}
/*
* Displaying
*/
- (void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView *)controlView
{
[[GSTheme theme] drawBrowserInteriorWithFrame: cellFrame
withCell: self
inView: controlView
withImage: [self image]
alternateImage: [self alternateImage]
isHighlighted: [self isHighlighted]
state: [self state]
isLeaf: [self isLeaf]];
}
/*
* NSCoding protocol
*/
- (void) encodeWithCoder: (NSCoder*)aCoder
{
[super encodeWithCoder: aCoder];
if ([aCoder allowsKeyedCoding])
{
// simply encodes prescence...
}
else
{
BOOL tmp;
tmp = _browsercell_is_leaf;
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &tmp];
tmp = _browsercell_is_loaded;
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &tmp];
[aCoder encodeObject: _alternateImage];
}
}
- (id) initWithCoder: (NSCoder*)aDecoder
{
self = [super initWithCoder: aDecoder];
if (nil == self)
return self;
if ([aDecoder allowsKeyedCoding])
{
// Nothing to decode...
}
else
{
BOOL tmp;
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &tmp];
[self setLeaf: tmp];
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &tmp];
[self setLoaded: tmp];
[aDecoder decodeValueOfObjCType: @encode(id) at: &_alternateImage];
}
return self;
}
@end
|