Adopted to programming standard. In [drawLabel:inRect:] use string

drawing method instead of PSshow().


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@9889 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
FredKiefer 2001-05-07 22:53:17 +00:00
parent 1c42ed5bb8
commit 2cc60288a9
2 changed files with 115 additions and 79 deletions

View file

@ -39,13 +39,14 @@ typedef enum {
@interface NSTabViewItem : NSObject <NSCoding> @interface NSTabViewItem : NSObject <NSCoding>
{ {
id item_ident; id _ident;
NSString *item_label; NSString *_label;
NSView *item_view; NSView *_view;
NSColor *item_color; NSColor *_color;
NSTabState item_state; NSTabState _state;
NSTabView *item_tabview; NSView *_first_responder;
NSRect item_rect; // cached NSTabView *_tabview;
NSRect _rect; // cached
} }
- (id) initWithIdentifier:(id)identifier; - (id) initWithIdentifier:(id)identifier;
@ -70,14 +71,15 @@ typedef enum {
- (void)drawLabel:(BOOL)shouldTruncateLabel - (void)drawLabel:(BOOL)shouldTruncateLabel
inRect:(NSRect)tabRect; inRect:(NSRect)tabRect;
@end
@interface NSTabViewItem (GNUstep)
// Non-spec // Non-spec
- (void)_setTabState:(NSTabState)tabState; - (void)_setTabState:(NSTabState)tabState;
- (void)_setTabView:(NSTabView *)tabView; - (void)_setTabView:(NSTabView *)tabView;
- (NSRect) _tabRect; - (NSRect) _tabRect;
- (NSString*)_truncatedLabel;
- (void) encodeWithCoder: (NSCoder*)aCoder;
- (id) initWithCoder: (NSCoder*)aDecoder;
@end @end
#endif // _GNUstep_H_NSTabViewItem #endif // _GNUstep_H_NSTabViewItem

View file

@ -30,24 +30,25 @@
#include <AppKit/NSTabViewItem.h> #include <AppKit/NSTabViewItem.h>
#include <AppKit/PSOperators.h> #include <AppKit/PSOperators.h>
#include <AppKit/NSGraphics.h> #include <AppKit/NSGraphics.h>
#include <AppKit/NSAttributedString.h>
@implementation NSTabViewItem @implementation NSTabViewItem
- (id) initWithIdentifier:(id)identifier - (id) initWithIdentifier:(id)identifier
{ {
[super init]; [super init];
ASSIGN(item_ident, identifier); ASSIGN(_ident, identifier);
item_state = NSBackgroundTab; _state = NSBackgroundTab;
return self; return self;
} }
- (void) dealloc - (void) dealloc
{ {
TEST_RELEASE(item_ident); TEST_RELEASE(_ident);
RELEASE(item_label); RELEASE(_label);
RELEASE(item_view); RELEASE(_view);
RELEASE(item_color); RELEASE(_color);
[super dealloc]; [super dealloc];
} }
@ -55,100 +56,98 @@
- (void)setIdentifier:(id)identifier - (void)setIdentifier:(id)identifier
{ {
ASSIGN(item_ident, identifier); ASSIGN(_ident, identifier);
} }
- (id)identifier - (id)identifier
{ {
return item_ident; return _ident;
} }
// Set label for item. // Set label for item.
- (void)setLabel:(NSString *)label - (void)setLabel:(NSString *)label
{ {
ASSIGN(item_label, label); ASSIGN(_label, label);
} }
- (NSString *)label - (NSString *)label
{ {
return item_label; return _label;
} }
- (NSSize)sizeOfLabel:(BOOL)shouldTruncateLabel - (NSSize)sizeOfLabel:(BOOL)shouldTruncateLabel
{ {
NSDictionary * attr = [[NSDictionary alloc] initWithObjectsAndKeys:
[_tabview font], NSFontAttributeName,
nil];
NSString *string;
NSSize rSize; NSSize rSize;
rSize.height = 12; if (shouldTruncateLabel)
{
string = [self _truncatedLabel];
}
else
{
string = _label;
}
if (shouldTruncateLabel) { rSize = [string sizeWithAttributes: attr];
// what is the algo to truncate? RELEASE(attr);
rSize.width = [[item_tabview font] widthOfString:item_label]; return rSize;
return rSize;
} else {
rSize.width = [[item_tabview font] widthOfString:item_label];
return rSize;
}
return NSZeroSize;
} }
// Set view to display when item is clicked. // Set view to display when item is clicked.
- (void)setView:(NSView *)view - (void)setView:(NSView *)view
{ {
ASSIGN(item_view, view); ASSIGN(_view, view);
} }
- (NSView *)view - (NSView *)view
{ {
return item_view; return _view;
} }
// Set color of tab surface. // Set color of tab surface.
- (void)setColor:(NSColor *)color - (void)setColor:(NSColor *)color
{ {
ASSIGN(item_color, color); ASSIGN(_color, color);
} }
- (NSColor *)color - (NSColor *)color
{ {
return item_color; return _color;
} }
// tab state // tab state
- (NSTabState)tabState - (NSTabState)tabState
{ {
return item_state; return _state;
} }
- (void)_setTabState:(NSTabState)tabState
{
item_state = tabState;
}
// Tab view, this is the "super" view. // Tab view, this is the "super" view.
- (void)_setTabView:(NSTabView *)tabView
{
item_tabview = tabView;
}
- (NSTabView *)tabView - (NSTabView *)tabView
{ {
return item_tabview; return _tabview;
} }
// First responder. // First responder.
- (void)setInitialFirstResponder:(NSView *)view - (void)setInitialFirstResponder:(NSView *)view
{ {
// We don't retain this.
_first_responder = view;
} }
- (id)initialFirstResponder - (id)initialFirstResponder
{ {
return nil; return _first_responder;
} }
// Draw item. // Draw item.
@ -157,23 +156,34 @@
inRect:(NSRect)tabRect inRect:(NSRect)tabRect
{ {
NSGraphicsContext *ctxt = GSCurrentContext(); NSGraphicsContext *ctxt = GSCurrentContext();
NSRect lRect; // NSRect lRect;
NSRect fRect; NSRect fRect;
NSDictionary *attr;
NSString *string;
item_rect = tabRect; if (shouldTruncateLabel)
{
string = [self _truncatedLabel];
}
else
{
string = _label;
}
_rect = tabRect;
DPSgsave(ctxt); DPSgsave(ctxt);
fRect = tabRect; fRect = tabRect;
if (item_state == NSSelectedTab) if (_state == NSSelectedTab)
{ {
fRect.origin.y -= 1; fRect.origin.y -= 1;
fRect.size.height += 1; fRect.size.height += 1;
[[NSColor controlBackgroundColor] set]; [[NSColor controlBackgroundColor] set];
NSRectFill(fRect); NSRectFill(fRect);
} }
else if (item_state == NSBackgroundTab) else if (_state == NSBackgroundTab)
{ {
[[NSColor controlBackgroundColor] set]; [[NSColor controlBackgroundColor] set];
NSRectFill(fRect); NSRectFill(fRect);
@ -183,49 +193,73 @@
[[NSColor controlBackgroundColor] set]; [[NSColor controlBackgroundColor] set];
} }
lRect = tabRect; attr = [[NSDictionary alloc] initWithObjectsAndKeys:
lRect.origin.y += 3; [_tabview font], NSFontAttributeName,
[[item_tabview font] set]; [NSColor blackColor], NSForegroundColorAttributeName,
nil];
DPSsetgray(ctxt, 0); // For some unclear reason, somehow connected with clipping,
DPSmoveto(ctxt, lRect.origin.x, lRect.origin.y); // drawInRect does not work here. But drawAtPoint works fine.
DPSshow(ctxt, [item_label cString]); [string drawAtPoint: NSMakePoint(tabRect.origin.x, NSMaxY(tabRect))
withAttributes: attr];
// lRect = tabRect;
// lRect.origin.y += 3;
// [_label drawInRect: lRect withAttributes: attr];
RELEASE(attr);
DPSgrestore(ctxt); DPSgrestore(ctxt);
} }
// Non spec
- (NSRect) _tabRect
{
return item_rect;
}
// NSCoding protocol. // NSCoding protocol.
- (void) encodeWithCoder: (NSCoder*)aCoder - (void) encodeWithCoder: (NSCoder*)aCoder
{ {
[super encodeWithCoder: aCoder]; [aCoder encodeObject:_ident];
[aCoder encodeObject:_label];
[aCoder encodeObject:item_ident]; [aCoder encodeObject:_view];
[aCoder encodeObject:item_label]; [aCoder encodeObject:_color];
[aCoder encodeObject:item_view]; [aCoder encodeValueOfObjCType: @encode(NSTabState) at: &_state];
[aCoder encodeObject:item_color]; [aCoder encodeObject:_first_responder];
[aCoder encodeValueOfObjCType: @encode(NSTabState) at: &item_state]; [aCoder encodeObject:_tabview];
[aCoder encodeObject:item_tabview];
} }
- (id) initWithCoder: (NSCoder*)aDecoder - (id) initWithCoder: (NSCoder*)aDecoder
{ {
[super initWithCoder: aDecoder]; [aDecoder decodeValueOfObjCType: @encode(id) at: &_ident];
[aDecoder decodeValueOfObjCType: @encode(id) at: &_label];
[aDecoder decodeValueOfObjCType: @encode(id) at: &item_ident]; [aDecoder decodeValueOfObjCType: @encode(id) at: &_view];
[aDecoder decodeValueOfObjCType: @encode(id) at: &item_label]; [aDecoder decodeValueOfObjCType: @encode(id) at: &_color];
[aDecoder decodeValueOfObjCType: @encode(id) at: &item_view]; [aDecoder decodeValueOfObjCType: @encode(NSTabState) at:&_state];
[aDecoder decodeValueOfObjCType: @encode(id) at: &item_color]; [aDecoder decodeValueOfObjCType: @encode(id) at: &_first_responder];
[aDecoder decodeValueOfObjCType: @encode(NSTabState) at:&item_state]; [aDecoder decodeValueOfObjCType: @encode(id) at: &_tabview];
[aDecoder decodeValueOfObjCType: @encode(id) at: &item_tabview];
return self; return self;
} }
@end @end
@implementation NSTabViewItem (GNUstep)
// Non spec
- (NSRect) _tabRect
{
return _rect;
}
- (void)_setTabState:(NSTabState)tabState
{
_state = tabState;
}
- (void)_setTabView:(NSTabView *)tabView
{
_tabview = tabView;
}
- (NSString*)_truncatedLabel
{
// FIXME: What is the algo to truncate?
return _label;
}
@end