mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-06-05 01:10:58 +00:00
Use rectOfPathComponentCell: to determine the frames of cells to be drawn.
This commit is contained in:
parent
d3322b62f2
commit
5cb4e41d17
4 changed files with 64 additions and 83 deletions
|
@ -33,8 +33,6 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
Class pathComponentCellClass;
|
||||
|
||||
enum {
|
||||
NSPathStyleStandard,
|
||||
NSPathStyleNavigationBar, // deprecated
|
||||
|
@ -59,8 +57,8 @@ typedef NSUInteger NSPathStyle;
|
|||
SEL _doubleAction;
|
||||
NSArray *_pathComponentCells;
|
||||
NSPathComponentCell *_clickedPathComponentCell;
|
||||
id _objectValue;
|
||||
NSControlSize _controlSize;
|
||||
// id _objectValue;
|
||||
// NSControlSize _controlSize;
|
||||
}
|
||||
|
||||
- (void)mouseEntered:(NSEvent *)event
|
||||
|
@ -77,8 +75,8 @@ typedef NSUInteger NSPathStyle;
|
|||
- (NSPathStyle) pathStyle;
|
||||
- (void) setPathStyle: (NSPathStyle)pathStyle;
|
||||
|
||||
- (void) setControlSize: (NSControlSize)size;
|
||||
- (void) setObjectValue: (id)obj;
|
||||
// - (void) setControlSize: (NSControlSize)size;
|
||||
// - (void) setObjectValue: (id)obj;
|
||||
|
||||
- (NSAttributedString *) placeholderAttributedString;
|
||||
- (void) setPlaceholderAttributedString: (NSAttributedString *)string;
|
||||
|
|
|
@ -42,11 +42,8 @@ extern "C" {
|
|||
|
||||
@interface NSPathControl : NSControl
|
||||
{
|
||||
NSColor *_backgroundColor;
|
||||
NSArray *_pathItems;
|
||||
id<NSPathControlDelegate> _delegate;
|
||||
id _target;
|
||||
SEL _action;
|
||||
NSDragOperation _localMask;
|
||||
NSDragOperation _remoteMask;
|
||||
NSTrackingRectTag _trackingTag;
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
#import "AppKit/NSImage.h"
|
||||
#import "AppKit/NSPathComponentCell.h"
|
||||
|
||||
Class pathComponentCellClass;
|
||||
|
||||
@interface NSPathCell (Private)
|
||||
+ (NSArray *) _generateCellsForURL: (NSURL *)url;
|
||||
@end
|
||||
|
@ -37,18 +39,31 @@
|
|||
|
||||
@implementation NSPathCell
|
||||
|
||||
+ (void) initialize
|
||||
{
|
||||
if (self == [NSPathCell class])
|
||||
{
|
||||
[self setVersion: 1.0];
|
||||
[self setPathComponentCellClass: [NSPathComponentCell class]];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)mouseEntered:(NSEvent *)event
|
||||
withFrame:(NSRect)frame
|
||||
inView:(NSView *)view
|
||||
{
|
||||
NSLog(@"Entered...");
|
||||
// This is the method where the expansion of the cell happens
|
||||
// if the path component cells are shortened.
|
||||
// This is currently not implemented.
|
||||
}
|
||||
|
||||
- (void)mouseExited:(NSEvent *)event
|
||||
withFrame:(NSRect)frame
|
||||
inView:(NSView *)view
|
||||
{
|
||||
NSLog(@"Exited...");
|
||||
// This is the method where the contraction of the cell happens
|
||||
// if the path component cells are shortened.
|
||||
// This is currently not implemented.
|
||||
}
|
||||
|
||||
- (void) setAllowedTypes: (NSArray *)types
|
||||
|
@ -71,16 +86,6 @@
|
|||
_pathStyle = pathStyle;
|
||||
}
|
||||
|
||||
- (void) setControlSize: (NSControlSize)size
|
||||
{
|
||||
_controlSize = size;
|
||||
}
|
||||
|
||||
- (void) setObjectValue: (id)obj
|
||||
{
|
||||
ASSIGN(_objectValue, obj);
|
||||
}
|
||||
|
||||
- (NSAttributedString *) placeholderAttributedString
|
||||
{
|
||||
return _placeholderAttributedString;
|
||||
|
@ -111,6 +116,13 @@
|
|||
ASSIGNCOPY(_backgroundColor, color);
|
||||
}
|
||||
|
||||
- (void) setObjectValue: (id)obj
|
||||
{
|
||||
NSLog(@"Called");
|
||||
[super setObjectValue: obj];
|
||||
[self setURL: obj];
|
||||
}
|
||||
|
||||
+ (Class) pathComponentCellClass
|
||||
{
|
||||
return pathComponentCellClass;
|
||||
|
@ -126,13 +138,11 @@
|
|||
inView:(NSView *)view
|
||||
{
|
||||
NSUInteger index = [_pathComponentCells indexOfObject: cell];
|
||||
NSRect rect = frame;
|
||||
CGFloat cellwidth = rect.size.width / [_pathComponentCells count];
|
||||
NSRect result = NSMakeRect(rect.origin.x,
|
||||
rect.origin.y + (cellwidth * index),
|
||||
cellwidth,
|
||||
rect.size.height);
|
||||
return result;
|
||||
CGFloat cellWidth = (frame.size.width / (CGFloat)[_pathComponentCells count]);
|
||||
return NSMakeRect(frame.origin.x + (cellWidth * (CGFloat)index),
|
||||
frame.origin.y,
|
||||
cellWidth,
|
||||
frame.size.height);
|
||||
}
|
||||
|
||||
- (NSPathComponentCell *)pathComponentCellAtPoint:(NSPoint)point
|
||||
|
@ -202,15 +212,14 @@
|
|||
{
|
||||
NSEnumerator *en = [_pathComponentCells objectEnumerator];
|
||||
NSPathComponentCell *cell = nil;
|
||||
CGFloat cell_width = (frame.size.width / (CGFloat)[_pathComponentCells count]);
|
||||
CGFloat current_x = 0.0;
|
||||
|
||||
while((cell = (NSPathComponentCell *)[en nextObject]) != nil)
|
||||
{
|
||||
NSRect f = NSMakeRect(current_x, 0.0, cell_width, frame.size.height);
|
||||
NSRect f = [self rectOfPathComponentCell: cell
|
||||
withFrame: frame
|
||||
inView: controlView];
|
||||
[cell drawInteriorWithFrame: f
|
||||
inView: controlView];
|
||||
current_x += cell_width;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,6 +58,15 @@ static NSNotificationCenter *nc = nil;
|
|||
}
|
||||
}
|
||||
|
||||
- (void) _resetTrackingRect
|
||||
{
|
||||
[[self superview] removeTrackingRect: _trackingTag];
|
||||
_trackingTag = [[self superview] addTrackingRect: [self frame]
|
||||
owner: self
|
||||
userData: nil
|
||||
assumeInside: YES];
|
||||
}
|
||||
|
||||
- (instancetype) init
|
||||
{
|
||||
self = [super init];
|
||||
|
@ -68,32 +77,29 @@ static NSNotificationCenter *nc = nil;
|
|||
[self setURL: nil];
|
||||
[self setDelegate: nil];
|
||||
[self setAllowedTypes: [NSArray arrayWithObject: NSFilenamesPboardType]];
|
||||
|
||||
[self removeTrackingRect: _trackingTag];
|
||||
_trackingTag = [self addTrackingRect: [self frame]
|
||||
owner: self
|
||||
userData: nil
|
||||
assumeInside: YES];
|
||||
|
||||
[self _resetTrackingRect];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[self removeTrackingRect: _trackingTag];
|
||||
RELEASE(_backgroundColor);
|
||||
[[self superview] removeTrackingRect: _trackingTag];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void) mouseEntered: (NSEvent *)event
|
||||
{
|
||||
NSLog(@"Entered");
|
||||
[_cell mouseEntered: event
|
||||
withFrame: [self frame]
|
||||
inView: self];
|
||||
}
|
||||
|
||||
- (void) mouseExited: (NSEvent *)event
|
||||
{
|
||||
NSLog(@"Exited");
|
||||
[_cell mouseExited: event
|
||||
withFrame: [self frame]
|
||||
inView: self];
|
||||
}
|
||||
|
||||
- (void) setPathStyle: (NSPathStyle)style
|
||||
|
@ -255,35 +261,15 @@ static NSNotificationCenter *nc = nil;
|
|||
|
||||
- (NSColor *) backgroundColor
|
||||
{
|
||||
return _backgroundColor;
|
||||
return [_cell backgroundColor];
|
||||
}
|
||||
|
||||
- (void) setBackgroundColor: (NSColor *)color
|
||||
{
|
||||
ASSIGN(_backgroundColor, color);
|
||||
[_cell setBackgroundColor: color];
|
||||
[self setNeedsDisplay];
|
||||
}
|
||||
|
||||
- (void) setAction: (SEL)action
|
||||
{
|
||||
_action = action;
|
||||
}
|
||||
|
||||
- (SEL) action
|
||||
{
|
||||
return _action;
|
||||
}
|
||||
|
||||
- (void) setTarget: (id)target
|
||||
{
|
||||
_target = target;
|
||||
}
|
||||
|
||||
- (id) target
|
||||
{
|
||||
return _target;
|
||||
}
|
||||
|
||||
- (void) _doMenuAction: (id)sender
|
||||
{
|
||||
NSArray *cells = [self pathComponentCells];
|
||||
|
@ -293,10 +279,10 @@ static NSNotificationCenter *nc = nil;
|
|||
NSPathComponentCell *cc = [cells objectAtIndex: ci];
|
||||
|
||||
[_cell _setClickedPathComponentCell: cc];
|
||||
if (_action)
|
||||
if ([[self cell] action])
|
||||
{
|
||||
[self sendAction: _action
|
||||
to: _target];
|
||||
[self sendAction: [[self cell] action]
|
||||
to: [[self cell] target]];
|
||||
}
|
||||
|
||||
// Tested on OSX it doesn't do this... it apparently only chooses
|
||||
|
@ -413,10 +399,10 @@ static NSNotificationCenter *nc = nil;
|
|||
withFrame: [self frame]
|
||||
inView: self];
|
||||
[_cell _setClickedPathComponentCell: pcc];
|
||||
if (_action)
|
||||
if ([[self cell] action])
|
||||
{
|
||||
[self sendAction: _action
|
||||
to: _target];
|
||||
[self sendAction: [[self cell] action]
|
||||
to: [[self cell] target]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -454,11 +440,7 @@ static NSNotificationCenter *nc = nil;
|
|||
- (void) setFrame: (NSRect)frame
|
||||
{
|
||||
[super setFrame: frame];
|
||||
[self removeTrackingRect: _trackingTag];
|
||||
_trackingTag = [self addTrackingRect: [self frame]
|
||||
owner: self
|
||||
userData: nil
|
||||
assumeInside: YES];
|
||||
[self _resetTrackingRect];
|
||||
}
|
||||
|
||||
- (instancetype) initWithCoder: (NSKeyedUnarchiver *)coder
|
||||
|
@ -492,13 +474,8 @@ static NSNotificationCenter *nc = nil;
|
|||
id t = [coder decodeObjectForKey: @"NSControlTarget"];
|
||||
[self setTarget: t];
|
||||
}
|
||||
|
||||
[self removeTrackingRect: _trackingTag];
|
||||
_trackingTag = [self addTrackingRect: [self frame]
|
||||
owner: self
|
||||
userData: nil
|
||||
assumeInside: YES];
|
||||
|
||||
|
||||
[self _resetTrackingRect];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue