Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Headers/AppKit/NSDatePickerCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ APPKIT_EXPORT_CLASS
NSDatePickerMode _datePickerMode;
NSDatePickerStyle _datePickerStyle;
BOOL _drawsBackground;
NSInteger _selectedField;
NSInteger _typedValue;
NSInteger _typedDigits;
}

- (NSColor *) backgroundColor;
Expand Down
81 changes: 81 additions & 0 deletions Source/NSDatePicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,21 @@
Boston, MA 02110-1301, USA.
*/

#import <Foundation/NSDate.h>
#import <Foundation/NSString.h>

#import "AppKit/NSDatePickerCell.h"
#import "AppKit/NSDatePicker.h"
#import "AppKit/NSEvent.h"

@interface NSDatePickerCell (Private)
- (BOOL) _handleKeyEvent: (NSEvent *)event;
- (BOOL) _selectFieldAtPoint: (NSPoint)point inRect: (NSRect)frame;
- (NSInteger) _stepperDirectionAtPoint: (NSPoint)point
inRect: (NSRect)frame
ofView: (NSView *)view;
- (BOOL) _stepSelectedFieldBy: (NSInteger)delta;
@end

static id usedCellClass = nil;

Expand All @@ -57,6 +68,76 @@ + (void) setCellClass: (Class)cellClass
usedCellClass = cellClass;
}

- (void) keyDown: (NSEvent *)theEvent
{
NSDate *before = [_cell dateValue];

if ([(NSDatePickerCell *)_cell _handleKeyEvent: theEvent])
{
NSDate *after = [_cell dateValue];

[self setNeedsDisplay: YES];
if (before == nil || ![before isEqualToDate: after])
{
[self sendAction: [self action] to: [self target]];
}
return;
}

[super keyDown: theEvent];
}

- (void) mouseDown: (NSEvent *)theEvent
{
NSDatePickerCell *cell = (NSDatePickerCell *)_cell;
NSPoint point;
NSDate *before;
NSInteger direction;

if (![self isEnabled])
{
[super mouseDown: theEvent];
return;
}

point = [self convertPoint: [theEvent locationInWindow] fromView: nil];
before = [cell dateValue];
direction = [cell _stepperDirectionAtPoint: point
inRect: _bounds
ofView: self];
if (direction == 0 && ![cell _selectFieldAtPoint: point inRect: _bounds])
{
[super mouseDown: theEvent];
return;
}

if ([[self window] firstResponder] != self)
{
[[self window] makeFirstResponder: self];
}
if (direction != 0)
{
[cell _stepSelectedFieldBy: direction];
}
[self setNeedsDisplay: YES];
if (before == nil || ![before isEqualToDate: [cell dateValue]])
{
[self sendAction: [self action] to: [self target]];
}
}

- (BOOL) becomeFirstResponder
{
[self setNeedsDisplay: YES];
return YES;
}

- (BOOL) resignFirstResponder
{
[self setNeedsDisplay: YES];
return YES;
}

- (NSColor *) backgroundColor
{
return [_cell backgroundColor];
Expand Down
Loading
Loading