mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-06-02 15:00:59 +00:00
Better helper methods for cell string drawing. Implement MacOSX 10.4
methods on NSForm and NSFormCell. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@25421 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
eef9e991e9
commit
561e8d0985
8 changed files with 320 additions and 220 deletions
16
ChangeLog
16
ChangeLog
|
@ -1,3 +1,17 @@
|
||||||
|
2007-08-29 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
|
* Headers/AppKit/NSCell.h: Export more private drawing methods.
|
||||||
|
* Source/NSCell.m (-_drawAttributedString): New helper method to
|
||||||
|
get the attributed string which should be drawn.
|
||||||
|
* Source/NSCell.m (-drawInteriorWithFrame:inView:): Use this method.
|
||||||
|
* Source/NSSecureTextFieldCell.m: Implement -_drawAttributedString
|
||||||
|
instead of -drawInteriorWithFrame:.
|
||||||
|
* Headers/AppKit/NSFormCell.h,
|
||||||
|
* Headers/AppKit/NSForm.h: Add MacOSX 10.4 methods.
|
||||||
|
* Source/NSForm.m: Implement these methods.
|
||||||
|
* Source/NSFormCell.m: Implement these methods. Rewrote drawing
|
||||||
|
code. Remove the color change notification handling.
|
||||||
|
|
||||||
2007-08-28 Fred Kiefer <FredKiefer@gmx.de>
|
2007-08-28 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
* Source/NSApplication.m (-_windowWillClose:): Don't call
|
* Source/NSApplication.m (-_windowWillClose:): Don't call
|
||||||
|
@ -7,7 +21,7 @@
|
||||||
|
|
||||||
2007-08-28 Fred Kiefer <FredKiefer@gmx.de>
|
2007-08-28 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
* Source/NSCell.m (#initialize): Increase version number.
|
* Source/NSCell.m (+initialize): Increase version number.
|
||||||
* Source/NSCell.m (-initWithCoder:): Correct values for the
|
* Source/NSCell.m (-initWithCoder:): Correct values for the
|
||||||
decoded action mask, as they changed on 2007-08-03.
|
decoded action mask, as they changed on 2007-08-03.
|
||||||
Fixes bug #20884.
|
Fixes bug #20884.
|
||||||
|
|
|
@ -484,6 +484,11 @@ enum {
|
||||||
- (void) _drawAttributedText: (NSAttributedString*)aString
|
- (void) _drawAttributedText: (NSAttributedString*)aString
|
||||||
inFrame: (NSRect)aRect;
|
inFrame: (NSRect)aRect;
|
||||||
- (BOOL) _sendsActionOn:(int)eventTypeMask;
|
- (BOOL) _sendsActionOn:(int)eventTypeMask;
|
||||||
|
- (NSAttributedString*) _drawAttributedString;
|
||||||
|
- (void) _drawBorderAndBackgroundWithFrame: (NSRect)cellFrame
|
||||||
|
inView: (NSView*)controlView;
|
||||||
|
- (void) _drawFocusRingWithFrame: (NSRect)cellFrame
|
||||||
|
inView: (NSView*)controlView;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
@ -64,6 +64,10 @@
|
||||||
- (void)setTextFont:(NSFont*)fontObject;
|
- (void)setTextFont:(NSFont*)fontObject;
|
||||||
- (void)setTitleAlignment:(NSTextAlignment)aMode;
|
- (void)setTitleAlignment:(NSTextAlignment)aMode;
|
||||||
- (void)setTitleFont:(NSFont*)fontObject;
|
- (void)setTitleFont:(NSFont*)fontObject;
|
||||||
|
#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST)
|
||||||
|
- (void) setTitleBaseWritingDirection: (NSWritingDirection)direction;
|
||||||
|
- (void) setTextBaseWritingDirection: (NSWritingDirection)direction;
|
||||||
|
#endif
|
||||||
|
|
||||||
//
|
//
|
||||||
// Getting a Cell
|
// Getting a Cell
|
||||||
|
|
|
@ -44,6 +44,8 @@
|
||||||
// YES if the titleWidth is automatically computed
|
// YES if the titleWidth is automatically computed
|
||||||
#define _formcell_auto_title_width _cell.subclass_bool_one
|
#define _formcell_auto_title_width _cell.subclass_bool_one
|
||||||
NSCell* _titleCell;
|
NSCell* _titleCell;
|
||||||
|
#define _formcell_placeholder_is_attributed_string _cell.subclass_bool_two
|
||||||
|
id _placeholder;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -67,7 +69,15 @@
|
||||||
- (void)setAttributedTitle:(NSAttributedString *)anAttributedString;
|
- (void)setAttributedTitle:(NSAttributedString *)anAttributedString;
|
||||||
- (void)setTitleWithMnemonic:(NSString *)titleWithAmpersand;
|
- (void)setTitleWithMnemonic:(NSString *)titleWithAmpersand;
|
||||||
#endif
|
#endif
|
||||||
|
#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST)
|
||||||
|
- (NSAttributedString*)placeholderAttributedString;
|
||||||
|
- (NSString*)placeholderString;
|
||||||
|
- (void)setPlaceholderAttributedString:(NSAttributedString*)string;
|
||||||
|
- (void)setPlaceholderString:(NSString*)string;
|
||||||
|
|
||||||
|
- (NSWritingDirection)titleBaseWritingDirection;
|
||||||
|
- (void)setTitleBaseWritingDirection:(NSWritingDirection)writingDirection;
|
||||||
|
#endif
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
|
173
Source/NSCell.m
173
Source/NSCell.m
|
@ -1943,57 +1943,32 @@ static NSColor *shadowCol;
|
||||||
switch (_cell.type)
|
switch (_cell.type)
|
||||||
{
|
{
|
||||||
case NSTextCellType:
|
case NSTextCellType:
|
||||||
{
|
[self _drawAttributedText: [self _drawAttributedString]
|
||||||
if (!_cell.is_disabled)
|
inFrame: cellFrame];
|
||||||
{
|
break;
|
||||||
[self _drawAttributedText: [self attributedStringValue]
|
|
||||||
inFrame: cellFrame];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
NSAttributedString *attrStr = [self attributedStringValue];
|
|
||||||
NSDictionary *attribs;
|
|
||||||
NSMutableDictionary *newAttribs;
|
|
||||||
|
|
||||||
attribs = [attrStr attributesAtIndex: 0
|
|
||||||
effectiveRange: NULL];
|
|
||||||
newAttribs = [NSMutableDictionary
|
|
||||||
dictionaryWithDictionary: attribs];
|
|
||||||
[newAttribs setObject: [NSColor disabledControlTextColor]
|
|
||||||
forKey: NSForegroundColorAttributeName];
|
|
||||||
|
|
||||||
attrStr = [[NSAttributedString alloc]
|
|
||||||
initWithString: [attrStr string]
|
|
||||||
attributes: newAttribs];
|
|
||||||
[self _drawAttributedText: attrStr
|
|
||||||
inFrame: cellFrame];
|
|
||||||
RELEASE(attrStr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case NSImageCellType:
|
case NSImageCellType:
|
||||||
if (_cell_image)
|
if (_cell_image)
|
||||||
{
|
{
|
||||||
NSSize size;
|
NSSize size;
|
||||||
NSPoint position;
|
NSPoint position;
|
||||||
|
|
||||||
size = [_cell_image size];
|
size = [_cell_image size];
|
||||||
position.x = MAX(NSMidX(cellFrame) - (size.width/2.),0.);
|
position.x = MAX(NSMidX(cellFrame) - (size.width/2.),0.);
|
||||||
position.y = MAX(NSMidY(cellFrame) - (size.height/2.),0.);
|
position.y = MAX(NSMidY(cellFrame) - (size.height/2.),0.);
|
||||||
/*
|
/*
|
||||||
* Images are always drawn with their bottom-left corner
|
* Images are always drawn with their bottom-left corner
|
||||||
* at the origin so we must adjust the position to take
|
* at the origin so we must adjust the position to take
|
||||||
* account of a flipped view.
|
* account of a flipped view.
|
||||||
*/
|
*/
|
||||||
if ([controlView isFlipped])
|
if ([controlView isFlipped])
|
||||||
position.y += size.height;
|
position.y += size.height;
|
||||||
[_cell_image compositeToPoint: position operation: NSCompositeSourceOver];
|
[_cell_image compositeToPoint: position operation: NSCompositeSourceOver];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NSNullCellType:
|
case NSNullCellType:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// NB: We don't do any highlighting to make it easier for subclasses
|
// NB: We don't do any highlighting to make it easier for subclasses
|
||||||
|
@ -2001,44 +1976,6 @@ static NSColor *shadowCol;
|
||||||
// prettyfying
|
// prettyfying
|
||||||
}
|
}
|
||||||
|
|
||||||
// Private helper method overridden in subclasses
|
|
||||||
- (void) _drawBorderAndBackgroundWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
|
|
||||||
{
|
|
||||||
if (_cell.is_bordered)
|
|
||||||
{
|
|
||||||
[shadowCol set];
|
|
||||||
NSFrameRect(cellFrame);
|
|
||||||
}
|
|
||||||
else if (_cell.is_bezeled)
|
|
||||||
{
|
|
||||||
[[GSTheme theme] drawWhiteBezel: cellFrame withClip: NSZeroRect];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Private helper method
|
|
||||||
- (void) _drawFocusRingWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
|
|
||||||
{
|
|
||||||
if (_cell.shows_first_responder
|
|
||||||
&& [[controlView window] firstResponder] == controlView)
|
|
||||||
{
|
|
||||||
switch (_cell.focus_ring_type)
|
|
||||||
{
|
|
||||||
case NSFocusRingTypeDefault:
|
|
||||||
[[GSTheme theme] drawFocusFrame: [self drawingRectForBounds:
|
|
||||||
cellFrame]
|
|
||||||
view: controlView];
|
|
||||||
break;
|
|
||||||
case NSFocusRingTypeExterior:
|
|
||||||
[[GSTheme theme] drawFocusFrame: cellFrame
|
|
||||||
view: controlView];
|
|
||||||
break;
|
|
||||||
case NSFocusRingTypeNone:
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**<p>Draws the cell in <var>controlView</var></p>
|
/**<p>Draws the cell in <var>controlView</var></p>
|
||||||
*/
|
*/
|
||||||
- (void) drawWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
|
- (void) drawWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
|
||||||
|
@ -2802,6 +2739,33 @@ static NSColor *shadowCol;
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Private internal method, returns an attributed string to display.
|
||||||
|
*/
|
||||||
|
- (NSAttributedString*) _drawAttributedString
|
||||||
|
{
|
||||||
|
if (!_cell.is_disabled)
|
||||||
|
{
|
||||||
|
return [self attributedStringValue];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NSAttributedString *attrStr = [self attributedStringValue];
|
||||||
|
NSDictionary *attribs;
|
||||||
|
NSMutableDictionary *newAttribs;
|
||||||
|
|
||||||
|
attribs = [attrStr attributesAtIndex: 0
|
||||||
|
effectiveRange: NULL];
|
||||||
|
newAttribs = [NSMutableDictionary dictionaryWithDictionary: attribs];
|
||||||
|
[newAttribs setObject: [NSColor disabledControlTextColor]
|
||||||
|
forKey: NSForegroundColorAttributeName];
|
||||||
|
|
||||||
|
return AUTORELEASE([[NSAttributedString alloc]
|
||||||
|
initWithString: [attrStr string]
|
||||||
|
attributes: newAttribs]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private internal method to display an attributed string.
|
* Private internal method to display an attributed string.
|
||||||
*/
|
*/
|
||||||
|
@ -2849,6 +2813,45 @@ static NSColor *shadowCol;
|
||||||
RELEASE (attributes);
|
RELEASE (attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Private helper method overridden in subclasses
|
||||||
|
- (void) _drawBorderAndBackgroundWithFrame: (NSRect)cellFrame
|
||||||
|
inView: (NSView*)controlView
|
||||||
|
{
|
||||||
|
if (_cell.is_bordered)
|
||||||
|
{
|
||||||
|
[shadowCol set];
|
||||||
|
NSFrameRect(cellFrame);
|
||||||
|
}
|
||||||
|
else if (_cell.is_bezeled)
|
||||||
|
{
|
||||||
|
[[GSTheme theme] drawWhiteBezel: cellFrame withClip: NSZeroRect];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Private helper method
|
||||||
|
- (void) _drawFocusRingWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
|
||||||
|
{
|
||||||
|
if (_cell.shows_first_responder
|
||||||
|
&& [[controlView window] firstResponder] == controlView)
|
||||||
|
{
|
||||||
|
switch (_cell.focus_ring_type)
|
||||||
|
{
|
||||||
|
case NSFocusRingTypeDefault:
|
||||||
|
[[GSTheme theme] drawFocusFrame: [self drawingRectForBounds:
|
||||||
|
cellFrame]
|
||||||
|
view: controlView];
|
||||||
|
break;
|
||||||
|
case NSFocusRingTypeExterior:
|
||||||
|
[[GSTheme theme] drawFocusFrame: cellFrame
|
||||||
|
view: controlView];
|
||||||
|
break;
|
||||||
|
case NSFocusRingTypeNone:
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (BOOL) _sendsActionOn:(int)eventTypeMask
|
- (BOOL) _sendsActionOn:(int)eventTypeMask
|
||||||
{
|
{
|
||||||
return (_action_mask & eventTypeMask);
|
return (_action_mask & eventTypeMask);
|
||||||
|
|
|
@ -58,32 +58,32 @@ static Class defaultCellClass = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) initWithFrame: (NSRect)frameRect
|
- (id) initWithFrame: (NSRect)frameRect
|
||||||
mode: (int)aMode
|
mode: (int)aMode
|
||||||
cellClass: (Class)class
|
cellClass: (Class)class
|
||||||
numberOfRows: (int)rowsHigh
|
numberOfRows: (int)rowsHigh
|
||||||
numberOfColumns: (int)colsWide
|
numberOfColumns: (int)colsWide
|
||||||
{
|
{
|
||||||
self = [super initWithFrame: (NSRect)frameRect
|
self = [super initWithFrame: (NSRect)frameRect
|
||||||
mode: (int)aMode
|
mode: (int)aMode
|
||||||
cellClass: (Class)class
|
cellClass: (Class)class
|
||||||
numberOfRows: (int)rowsHigh
|
numberOfRows: (int)rowsHigh
|
||||||
numberOfColumns: (int)colsWide];
|
numberOfColumns: (int)colsWide];
|
||||||
|
|
||||||
[self setIntercellSpacing: NSMakeSize (0, 4)];
|
[self setIntercellSpacing: NSMakeSize (0, 4)];
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) initWithFrame: (NSRect)frameRect
|
- (id) initWithFrame: (NSRect)frameRect
|
||||||
mode: (int)aMode
|
mode: (int)aMode
|
||||||
prototype: (NSCell*)prototype
|
prototype: (NSCell*)prototype
|
||||||
numberOfRows: (int)rowsHigh
|
numberOfRows: (int)rowsHigh
|
||||||
numberOfColumns: (int)colsWide
|
numberOfColumns: (int)colsWide
|
||||||
{
|
{
|
||||||
self = [super initWithFrame: (NSRect)frameRect
|
self = [super initWithFrame: (NSRect)frameRect
|
||||||
mode: (int)aMode
|
mode: (int)aMode
|
||||||
prototype: (NSCell*)prototype
|
prototype: (NSCell*)prototype
|
||||||
numberOfRows: (int)rowsHigh
|
numberOfRows: (int)rowsHigh
|
||||||
numberOfColumns: (int)colsWide];
|
numberOfColumns: (int)colsWide];
|
||||||
|
|
||||||
[self setIntercellSpacing: NSMakeSize (0, 4)];
|
[self setIntercellSpacing: NSMakeSize (0, 4)];
|
||||||
return self;
|
return self;
|
||||||
|
@ -103,7 +103,7 @@ static Class defaultCellClass = nil;
|
||||||
<p>See Also: -addEntry: -removeEntryAtIndex:</p>
|
<p>See Also: -addEntry: -removeEntryAtIndex:</p>
|
||||||
*/
|
*/
|
||||||
- (NSFormCell*) insertEntry: (NSString*)title
|
- (NSFormCell*) insertEntry: (NSString*)title
|
||||||
atIndex: (int)index
|
atIndex: (int)index
|
||||||
{
|
{
|
||||||
NSFormCell *new_cell = [[[isa cellClass] alloc] initTextCell: title];
|
NSFormCell *new_cell = [[[isa cellClass] alloc] initTextCell: title];
|
||||||
|
|
||||||
|
@ -196,6 +196,16 @@ static Class defaultCellClass = nil;
|
||||||
[self setCellSize: size];
|
[self setCellSize: size];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**<p>Sets the size of the frame to aSize</p>
|
||||||
|
<p>See Also: [NSView-setFrameSize:]</p>
|
||||||
|
*/
|
||||||
|
- (void) setFrameSize: (NSSize)aSize
|
||||||
|
{
|
||||||
|
[super setFrameSize: aSize];
|
||||||
|
// Set the width of the entries independent of autosizesCells
|
||||||
|
_cellSize.width = _bounds.size.width;
|
||||||
|
}
|
||||||
|
|
||||||
/** <p>Sets the spacing between all entries to spacing. By default
|
/** <p>Sets the spacing between all entries to spacing. By default
|
||||||
the spacing is 4.</p><p>See Also: [NSMatrix-setIntercellSpacing:]</p>
|
the spacing is 4.</p><p>See Also: [NSMatrix-setIntercellSpacing:]</p>
|
||||||
*/
|
*/
|
||||||
|
@ -268,6 +278,34 @@ static Class defaultCellClass = nil;
|
||||||
[[self cellAtRow: i column: 0] setFont: fontObject];
|
[[self cellAtRow: i column: 0] setFont: fontObject];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** <p>Sets the title writing direction to direction for all entries</p>
|
||||||
|
<p>See Also: [NSFormCell-setTitleBaseWritingDirection:] -setTextBaseWritingDirection:</p>
|
||||||
|
*/
|
||||||
|
- (void) setTitleBaseWritingDirection: (NSWritingDirection)direction
|
||||||
|
{
|
||||||
|
int i, count = [self numberOfRows];
|
||||||
|
|
||||||
|
/* Set the writing direction attribute to the cell prototype */
|
||||||
|
[[self prototype] setTitleBaseWritingDirection: direction];
|
||||||
|
|
||||||
|
for (i = 0; i < count; i++)
|
||||||
|
[[self cellAtRow: i column: 0] setTitleBaseWritingDirection: direction];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** <p>Sets the contents writing direction to direction for all entries</p>
|
||||||
|
<p>See Also: [NSCell-setBaseWritingDirection:] -setTitleBaseWritingDirection:</p>
|
||||||
|
*/
|
||||||
|
- (void) setTextBaseWritingDirection: (NSWritingDirection)direction
|
||||||
|
{
|
||||||
|
int i, count = [self numberOfRows];
|
||||||
|
|
||||||
|
/* Set the writing direction attribute to the cell prototype */
|
||||||
|
[[self prototype] setBaseWritingDirection: direction];
|
||||||
|
|
||||||
|
for (i = 0; i < count; i++)
|
||||||
|
[[self cellAtRow: i column: 0] setBaseWritingDirection: direction];
|
||||||
|
}
|
||||||
|
|
||||||
/**<p>Returns the index of the entry specified by aTag or -1 if aTag is not
|
/**<p>Returns the index of the entry specified by aTag or -1 if aTag is not
|
||||||
found in entries.</p><p>See Also: [NSMatrix-cellAtRow:column:]</p>
|
found in entries.</p><p>See Also: [NSMatrix-cellAtRow:column:]</p>
|
||||||
*/
|
*/
|
||||||
|
@ -322,7 +360,7 @@ static Class defaultCellClass = nil;
|
||||||
{
|
{
|
||||||
candidate_title_width = [_cells[i][0] titleWidth];
|
candidate_title_width = [_cells[i][0] titleWidth];
|
||||||
if (candidate_title_width > new_title_width)
|
if (candidate_title_width > new_title_width)
|
||||||
new_title_width = candidate_title_width;
|
new_title_width = candidate_title_width;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Suggest this max as title width to all cells
|
// Suggest this max as title width to all cells
|
||||||
|
@ -351,7 +389,7 @@ static Class defaultCellClass = nil;
|
||||||
id theCell = [self cellAtIndex: index];
|
id theCell = [self cellAtIndex: index];
|
||||||
|
|
||||||
[theCell drawWithFrame: [self cellFrameAtRow: index column: 0]
|
[theCell drawWithFrame: [self cellFrameAtRow: index column: 0]
|
||||||
inView: self];
|
inView: self];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) drawCellAtRow: (int)row column: (int)column
|
- (void) drawCellAtRow: (int)row column: (int)column
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <Foundation/NSNotification.h>
|
#include <Foundation/NSNotification.h>
|
||||||
|
#include "AppKit/NSAttributedString.h"
|
||||||
#include "AppKit/NSColor.h"
|
#include "AppKit/NSColor.h"
|
||||||
#include "AppKit/NSFormCell.h"
|
#include "AppKit/NSFormCell.h"
|
||||||
#include "AppKit/NSFont.h"
|
#include "AppKit/NSFont.h"
|
||||||
|
@ -36,19 +37,6 @@
|
||||||
#include "AppKit/NSTextFieldCell.h"
|
#include "AppKit/NSTextFieldCell.h"
|
||||||
#include "GNUstepGUI/GSTheme.h"
|
#include "GNUstepGUI/GSTheme.h"
|
||||||
|
|
||||||
static NSColor *shadowCol;
|
|
||||||
|
|
||||||
@interface NSFormCell (PrivateColor)
|
|
||||||
+ (void) _systemColorsChanged: (NSNotification*)n;
|
|
||||||
@end
|
|
||||||
|
|
||||||
@implementation NSFormCell (PrivateColor)
|
|
||||||
+ (void) _systemColorsChanged: (NSNotification*)n
|
|
||||||
{
|
|
||||||
ASSIGN(shadowCol, [NSColor controlDarkShadowColor]);
|
|
||||||
}
|
|
||||||
@end
|
|
||||||
|
|
||||||
/** <p>TODO Description </p>
|
/** <p>TODO Description </p>
|
||||||
*/
|
*/
|
||||||
@implementation NSFormCell
|
@implementation NSFormCell
|
||||||
|
@ -57,12 +45,6 @@ static NSColor *shadowCol;
|
||||||
if (self == [NSFormCell class])
|
if (self == [NSFormCell class])
|
||||||
{
|
{
|
||||||
[self setVersion: 1];
|
[self setVersion: 1];
|
||||||
[[NSNotificationCenter defaultCenter]
|
|
||||||
addObserver: self
|
|
||||||
selector: @selector(_systemColorsChanged:)
|
|
||||||
name: NSSystemColorsDidChangeNotification
|
|
||||||
object: nil];
|
|
||||||
[self _systemColorsChanged: nil];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,6 +77,7 @@ static NSColor *shadowCol;
|
||||||
- (void)dealloc
|
- (void)dealloc
|
||||||
{
|
{
|
||||||
RELEASE(_titleCell);
|
RELEASE(_titleCell);
|
||||||
|
TEST_RELEASE(_placeholder);
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,7 +90,7 @@ static NSColor *shadowCol;
|
||||||
return [_titleCell isOpaque] && [super isOpaque];
|
return [_titleCell isOpaque] && [super isOpaque];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setAttributedTitle:(NSAttributedString *)anAttributedString
|
- (void)setAttributedTitle: (NSAttributedString *)anAttributedString
|
||||||
{
|
{
|
||||||
[_titleCell setAttributedStringValue: anAttributedString];
|
[_titleCell setAttributedStringValue: anAttributedString];
|
||||||
if (_formcell_auto_title_width)
|
if (_formcell_auto_title_width)
|
||||||
|
@ -116,8 +99,8 @@ static NSColor *shadowCol;
|
||||||
_displayedTitleWidth = -1;
|
_displayedTitleWidth = -1;
|
||||||
// Update the control(s)
|
// Update the control(s)
|
||||||
[[NSNotificationCenter defaultCenter]
|
[[NSNotificationCenter defaultCenter]
|
||||||
postNotificationName: _NSFormCellDidChangeTitleWidthNotification
|
postNotificationName: _NSFormCellDidChangeTitleWidthNotification
|
||||||
object: self];
|
object: self];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,8 +117,8 @@ static NSColor *shadowCol;
|
||||||
_displayedTitleWidth = -1;
|
_displayedTitleWidth = -1;
|
||||||
// Update the control(s)
|
// Update the control(s)
|
||||||
[[NSNotificationCenter defaultCenter]
|
[[NSNotificationCenter defaultCenter]
|
||||||
postNotificationName: _NSFormCellDidChangeTitleWidthNotification
|
postNotificationName: _NSFormCellDidChangeTitleWidthNotification
|
||||||
object: self];
|
object: self];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,8 +131,8 @@ static NSColor *shadowCol;
|
||||||
_displayedTitleWidth = -1;
|
_displayedTitleWidth = -1;
|
||||||
// Update the control(s)
|
// Update the control(s)
|
||||||
[[NSNotificationCenter defaultCenter]
|
[[NSNotificationCenter defaultCenter]
|
||||||
postNotificationName: _NSFormCellDidChangeTitleWidthNotification
|
postNotificationName: _NSFormCellDidChangeTitleWidthNotification
|
||||||
object: self];
|
object: self];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,7 +141,7 @@ static NSColor *shadowCol;
|
||||||
id="NSTextAlignment">NSTextAlignment</ref> for more informations.
|
id="NSTextAlignment">NSTextAlignment</ref> for more informations.
|
||||||
</p><p>See Also: -titleAlignment [NSCell-setAlignment:]</p>
|
</p><p>See Also: -titleAlignment [NSCell-setAlignment:]</p>
|
||||||
*/
|
*/
|
||||||
- (void)setTitleAlignment:(NSTextAlignment)mode
|
- (void)setTitleAlignment: (NSTextAlignment)mode
|
||||||
{
|
{
|
||||||
[_titleCell setAlignment: mode];
|
[_titleCell setAlignment: mode];
|
||||||
}
|
}
|
||||||
|
@ -175,8 +158,8 @@ static NSColor *shadowCol;
|
||||||
_displayedTitleWidth = -1;
|
_displayedTitleWidth = -1;
|
||||||
// Update the control(s)
|
// Update the control(s)
|
||||||
[[NSNotificationCenter defaultCenter]
|
[[NSNotificationCenter defaultCenter]
|
||||||
postNotificationName: _NSFormCellDidChangeTitleWidthNotification
|
postNotificationName: _NSFormCellDidChangeTitleWidthNotification
|
||||||
object: self];
|
object: self];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,6 +216,22 @@ static NSColor *shadowCol;
|
||||||
return [_titleCell font];
|
return [_titleCell font];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** <p>Returns the writing direction of the NSFormCell's title</p>
|
||||||
|
<p>See Also: -setTitleBaseWritingDirection: [NSCell-baseWritingDirection]</p>
|
||||||
|
*/
|
||||||
|
- (NSWritingDirection)titleBaseWritingDirection
|
||||||
|
{
|
||||||
|
return [_titleCell baseWritingDirection];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** <p>Sets the writing direction of the NSFormCell's title</p>
|
||||||
|
<p>See Also: -titleBaseWritingDirection: [NSCell-setBaseWritingDirection]</p>
|
||||||
|
*/
|
||||||
|
- (void)setTitleBaseWritingDirection: (NSWritingDirection)writingDirection
|
||||||
|
{
|
||||||
|
[_titleCell setBaseWritingDirection: writingDirection];
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Warning: this method returns the width of the title; the width the
|
// Warning: this method returns the width of the title; the width the
|
||||||
// title would have if the cell was the only cell in the form. This
|
// title would have if the cell was the only cell in the form. This
|
||||||
|
@ -262,12 +261,48 @@ static NSColor *shadowCol;
|
||||||
NSSize titleSize = [_titleCell cellSize];
|
NSSize titleSize = [_titleCell cellSize];
|
||||||
|
|
||||||
if (aSize.width > titleSize.width)
|
if (aSize.width > titleSize.width)
|
||||||
return titleSize.width;
|
return titleSize.width;
|
||||||
else
|
else
|
||||||
return aSize.width;
|
return aSize.width;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSAttributedString*)placeholderAttributedString
|
||||||
|
{
|
||||||
|
if (_formcell_placeholder_is_attributed_string == YES)
|
||||||
|
{
|
||||||
|
return (NSAttributedString*)_placeholder;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSString*)placeholderString
|
||||||
|
{
|
||||||
|
if (_formcell_placeholder_is_attributed_string == YES)
|
||||||
|
{
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return (NSString*)_placeholder;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setPlaceholderAttributedString: (NSAttributedString*)string
|
||||||
|
{
|
||||||
|
ASSIGN(_placeholder, string);
|
||||||
|
_formcell_placeholder_is_attributed_string = YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setPlaceholderString: (NSString*)string
|
||||||
|
{
|
||||||
|
ASSIGN(_placeholder, string);
|
||||||
|
_formcell_placeholder_is_attributed_string = NO;
|
||||||
|
}
|
||||||
|
|
||||||
// Updates the title width. The width of aRect is the new title width
|
// Updates the title width. The width of aRect is the new title width
|
||||||
// to display. Invoked by NSForm to align the editable parts of the
|
// to display. Invoked by NSForm to align the editable parts of the
|
||||||
// cells.
|
// cells.
|
||||||
|
@ -318,61 +353,80 @@ static NSColor *shadowCol;
|
||||||
return [super drawingRectForBounds: theRect];
|
return [super drawingRectForBounds: theRect];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) drawWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
|
- (void) _drawBorderAndBackgroundWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
|
||||||
{
|
{
|
||||||
NSRect titleFrame = cellFrame;
|
|
||||||
NSRect borderedFrame = cellFrame;
|
NSRect borderedFrame = cellFrame;
|
||||||
|
|
||||||
// Save last view drawn to
|
|
||||||
if (_control_view != controlView)
|
|
||||||
_control_view = controlView;
|
|
||||||
|
|
||||||
// do nothing if cell's frame rect is zero
|
|
||||||
if (NSIsEmptyRect(cellFrame))
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Safety check
|
|
||||||
if (_displayedTitleWidth == -1)
|
|
||||||
_displayedTitleWidth = [self titleWidth];
|
|
||||||
|
|
||||||
//
|
|
||||||
// Draw title
|
|
||||||
//
|
|
||||||
titleFrame.size.width = _displayedTitleWidth;
|
|
||||||
[_titleCell drawWithFrame: titleFrame inView: controlView];
|
|
||||||
|
|
||||||
//
|
|
||||||
// Leave unfilled the space between titlecell and editable text.
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Draw border
|
// Draw border
|
||||||
//
|
//
|
||||||
borderedFrame.origin.x += _displayedTitleWidth + 3;
|
borderedFrame.origin.x += _displayedTitleWidth + 3;
|
||||||
borderedFrame.size.width -= _displayedTitleWidth + 3;
|
borderedFrame.size.width -= _displayedTitleWidth + 3;
|
||||||
|
|
||||||
if (NSIsEmptyRect(borderedFrame))
|
[super _drawBorderAndBackgroundWithFrame: borderedFrame inView: controlView];
|
||||||
return;
|
// Draw text background
|
||||||
|
[[NSColor textBackgroundColor] set];
|
||||||
if (_cell.is_bordered)
|
NSRectFill([self drawingRectForBounds: cellFrame]);
|
||||||
{
|
}
|
||||||
[shadowCol set];
|
|
||||||
NSFrameRect(borderedFrame);
|
|
||||||
}
|
|
||||||
else if (_cell.is_bezeled)
|
|
||||||
{
|
|
||||||
NSRect frame;
|
|
||||||
|
|
||||||
frame = [[GSTheme theme] drawWhiteBezel: borderedFrame
|
- (void) drawWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
|
||||||
withClip: NSZeroRect];
|
{
|
||||||
[[NSColor textBackgroundColor] set];
|
NSRect titleFrame = cellFrame;
|
||||||
NSRectFill (frame);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
// Safety check
|
||||||
// Draw interior
|
if (_displayedTitleWidth == -1)
|
||||||
//
|
_displayedTitleWidth = [self titleWidth];
|
||||||
[self drawInteriorWithFrame: cellFrame inView: controlView];
|
|
||||||
|
// Draw title
|
||||||
|
titleFrame.size.width = _displayedTitleWidth;
|
||||||
|
[_titleCell drawWithFrame: titleFrame inView: controlView];
|
||||||
|
|
||||||
|
// Draw text
|
||||||
|
[super drawWithFrame: cellFrame inView: controlView];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Attributed string that will be displayed.
|
||||||
|
*/
|
||||||
|
- (NSAttributedString*)_drawAttributedString
|
||||||
|
{
|
||||||
|
NSAttributedString *attrStr;
|
||||||
|
|
||||||
|
attrStr = [super _drawAttributedString];
|
||||||
|
if (attrStr == nil)
|
||||||
|
{
|
||||||
|
attrStr = [self placeholderAttributedString];
|
||||||
|
if (attrStr == nil)
|
||||||
|
{
|
||||||
|
NSString *string;
|
||||||
|
NSDictionary *attributes;
|
||||||
|
NSMutableDictionary *newAttribs;
|
||||||
|
|
||||||
|
string = [self placeholderString];
|
||||||
|
if (string == nil)
|
||||||
|
{
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
attributes = [self _nonAutoreleasedTypingAttributes];
|
||||||
|
newAttribs = [NSMutableDictionary
|
||||||
|
dictionaryWithDictionary: attributes];
|
||||||
|
[newAttribs setObject: [NSColor disabledControlTextColor]
|
||||||
|
forKey: NSForegroundColorAttributeName];
|
||||||
|
|
||||||
|
return AUTORELEASE([[NSAttributedString alloc]
|
||||||
|
initWithString: string
|
||||||
|
attributes: newAttribs]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return attrStr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return attrStr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -387,6 +441,7 @@ static NSColor *shadowCol;
|
||||||
title cell of the copied cell, the string value of the title cell
|
title cell of the copied cell, the string value of the title cell
|
||||||
of the original cell would be changed too ! */
|
of the original cell would be changed too ! */
|
||||||
c->_titleCell = [_titleCell copyWithZone: zone];
|
c->_titleCell = [_titleCell copyWithZone: zone];
|
||||||
|
c->_placeholder = [_placeholder copyWithZone: zone];
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
@ -399,9 +454,9 @@ static NSColor *shadowCol;
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
if ([self stringValue] != nil)
|
if ([self stringValue] != nil)
|
||||||
{
|
{
|
||||||
[aCoder encodeObject: [self stringValue] forKey: @"NSContents"];
|
[aCoder encodeObject: [self stringValue] forKey: @"NSContents"];
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
[aCoder encodeFloat: [self titleWidth] forKey: @"NSTitleWidth"];
|
[aCoder encodeFloat: [self titleWidth] forKey: @"NSTitleWidth"];
|
||||||
[aCoder encodeObject: _titleCell forKey: @"NSTitleCell"];
|
[aCoder encodeObject: _titleCell forKey: @"NSTitleCell"];
|
||||||
|
@ -422,16 +477,16 @@ static NSColor *shadowCol;
|
||||||
{
|
{
|
||||||
if ([aDecoder containsValueForKey: @"NSContents"])
|
if ([aDecoder containsValueForKey: @"NSContents"])
|
||||||
{
|
{
|
||||||
[self setStringValue: [aDecoder decodeObjectForKey: @"NSContents"]];
|
[self setStringValue: [aDecoder decodeObjectForKey: @"NSContents"]];
|
||||||
}
|
}
|
||||||
if ([aDecoder containsValueForKey: @"NSTitleWidth"])
|
if ([aDecoder containsValueForKey: @"NSTitleWidth"])
|
||||||
{
|
{
|
||||||
[self setTitleWidth: [aDecoder decodeFloatForKey: @"NSTitleWidth"]];
|
[self setTitleWidth: [aDecoder decodeFloatForKey: @"NSTitleWidth"]];
|
||||||
}
|
}
|
||||||
if ([aDecoder containsValueForKey: @"NSTitleCell"])
|
if ([aDecoder containsValueForKey: @"NSTitleCell"])
|
||||||
{
|
{
|
||||||
ASSIGN(_titleCell, [aDecoder decodeObjectForKey: @"NSTitleCell"]);
|
ASSIGN(_titleCell, [aDecoder decodeObjectForKey: @"NSTitleCell"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -140,40 +140,13 @@
|
||||||
attributes: attributes]);
|
attributes: attributes]);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) drawInteriorWithFrame: (NSRect)cellFrame
|
- (NSAttributedString*) _drawAttributedString
|
||||||
inView: (NSView *)controlView
|
|
||||||
{
|
{
|
||||||
cellFrame = [self drawingRectForBounds: cellFrame];
|
|
||||||
|
|
||||||
/* Draw background, then ... */
|
|
||||||
if (_textfieldcell_draws_background)
|
|
||||||
{
|
|
||||||
if ([self isEnabled])
|
|
||||||
{
|
|
||||||
[_background_color set];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
[[NSColor controlBackgroundColor] set];
|
|
||||||
}
|
|
||||||
NSRectFill(cellFrame);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_echosBullets)
|
if (_echosBullets)
|
||||||
{
|
{
|
||||||
// Add spacing between border and inside
|
|
||||||
if (_cell.is_bordered || _cell.is_bezeled)
|
|
||||||
{
|
|
||||||
cellFrame.origin.x += 3;
|
|
||||||
cellFrame.size.width -= 6;
|
|
||||||
cellFrame.origin.y += 1;
|
|
||||||
cellFrame.size.height -= 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_cell.is_disabled)
|
if (!_cell.is_disabled)
|
||||||
{
|
{
|
||||||
[self _drawAttributedText: [self _replacementAttributedString]
|
return [self _replacementAttributedString];
|
||||||
inFrame: cellFrame];
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -188,17 +161,15 @@
|
||||||
[newAttribs setObject: [NSColor disabledControlTextColor]
|
[newAttribs setObject: [NSColor disabledControlTextColor]
|
||||||
forKey: NSForegroundColorAttributeName];
|
forKey: NSForegroundColorAttributeName];
|
||||||
|
|
||||||
attrStr = [[NSAttributedString alloc]
|
return AUTORELEASE([[NSAttributedString alloc]
|
||||||
initWithString: [attrStr string]
|
initWithString: [attrStr string]
|
||||||
attributes: newAttribs];
|
attributes: newAttribs]);
|
||||||
[self _drawAttributedText: attrStr
|
|
||||||
inFrame: cellFrame];
|
|
||||||
RELEASE(attrStr);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* .. do nothing. */
|
/* .. do nothing. */
|
||||||
|
return nil;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue