mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-22 13:10:59 +00:00
Merge branch 'master' into NSPathControl_branch
This commit is contained in:
commit
a390accec4
14 changed files with 616 additions and 12 deletions
20
ChangeLog
20
ChangeLog
|
@ -1,3 +1,23 @@
|
|||
2020-04-26 Gregory John Casamento <greg.casamento@gmail.com>
|
||||
|
||||
* Headers/Additions/GNUstepGUI/GSTheme.h: Add declarations
|
||||
for new drawing methods.
|
||||
* Headers/AppKit/AppKit.h: Add new headers
|
||||
* Headers/AppKit/NSAccessibilityProtocols.h
|
||||
* Headers/AppKit/NSCell.h: Add NSControlStateValue enum
|
||||
* Headers/AppKit/NSSwitch.h: Header for NSSwitch
|
||||
* MISSING: Remove NSSwitch
|
||||
* Source/GNUmakefile: Add .h and .m files
|
||||
* Source/GSThemeDrawing.m: Add drawing code for knob and
|
||||
switch basin.
|
||||
* Source/GSXib5KeyedUnarchiver.m: Add decoding for
|
||||
NSControlContents. Make sure enabled is YES when not
|
||||
present.
|
||||
* Source/NSColor.m: Minor changes
|
||||
* Source/NSMatrix.m: Remove unneeded code
|
||||
* Source/NSSwitch.m: Implementation of NSSwitch
|
||||
* Source/NSToolbarItem.m: Remove unneeded code
|
||||
|
||||
2020-04-13 Gregory John Casamento <greg.casamento@gmail.com>
|
||||
|
||||
* Headers/AppKit/AppKitErrors.h:
|
||||
|
|
|
@ -958,6 +958,20 @@ APPKIT_EXPORT NSString *GSThemeWillDeactivateNotification;
|
|||
*/
|
||||
- (void) drawStepperHighlightDownButton: (NSRect)aRect;
|
||||
|
||||
// NSSwitch drawing methods
|
||||
- (void) drawSwitchKnob: (NSRect)frame
|
||||
forState: (NSControlStateValue)value
|
||||
enabled: (BOOL)enabled;
|
||||
|
||||
|
||||
- (void) drawSwitchBezel: (NSRect)frame
|
||||
forState: (NSControlStateValue)v
|
||||
enabled: (BOOL)enabled;
|
||||
|
||||
- (void) drawSwitchInRect: (NSRect)rect
|
||||
forState: (NSControlStateValue)state
|
||||
enabled: (BOOL)enabled;
|
||||
|
||||
// NSSegmentedControl drawing methods
|
||||
|
||||
- (void) drawSegmentedControlSegment: (NSCell *)cell
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
|
||||
#import <AppKit/NSAccessibility.h>
|
||||
#import <AppKit/NSAccessibilityConstants.h>
|
||||
#import <AppKit/NSAccessibilityProtocols.h>
|
||||
#import <AppKit/NSActionCell.h>
|
||||
#import <AppKit/NSAnimationContext.h>
|
||||
#import <AppKit/NSAppearance.h>
|
||||
|
@ -216,6 +217,7 @@
|
|||
#import <AppKit/NSStepperTouchBarItem.h>
|
||||
#import <AppKit/NSStepper.h>
|
||||
#import <AppKit/NSStepperCell.h>
|
||||
#import <AppKit/NSSwitch.h>
|
||||
#import <AppKit/NSTableColumn.h>
|
||||
#import <AppKit/NSTableHeaderCell.h>
|
||||
#import <AppKit/NSTableHeaderView.h>
|
||||
|
|
61
Headers/AppKit/NSAccessibilityProtocols.h
Normal file
61
Headers/AppKit/NSAccessibilityProtocols.h
Normal file
|
@ -0,0 +1,61 @@
|
|||
/* Definition of class NSAccessibilityProtocols
|
||||
Copyright (C) 2020 Free Software Foundation, Inc.
|
||||
|
||||
By: Gregory John Casamento
|
||||
Date: Sun Apr 19 09:56:39 EDT 2020
|
||||
|
||||
This file is part of the GNUstep 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.1 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; if not, write to the Free
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110 USA.
|
||||
*/
|
||||
|
||||
#ifndef _NSAccessibilityProtocols_h_GNUSTEP_GUI_INCLUDE
|
||||
#define _NSAccessibilityProtocols_h_GNUSTEP_GUI_INCLUDE
|
||||
|
||||
#import <Foundation/NSObject.h>
|
||||
|
||||
#if OS_API_VERSION(MAC_OS_X_VERSION_10_10, GS_API_LATEST)
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
@protocol NSAccessibilityElement <NSObject>
|
||||
- (NSRect)accessibilityFrame;
|
||||
- (NSString *)accessibilityIdentifier;
|
||||
- (id)accessibilityParent;
|
||||
- (BOOL)isAccessibilityFocused;
|
||||
@end
|
||||
|
||||
@protocol NSAccessibilityButton <NSAccessibilityElement>
|
||||
- (NSString *)accessibilityLabel;
|
||||
- (BOOL)accessibilityPerformPress;
|
||||
@end
|
||||
|
||||
@protocol NSAccessibilitySwitch <NSAccessibilityButton>
|
||||
- (BOOL) accessibilityPerformDecrement;
|
||||
- (BOOL) accessibilityPerformIncrement;
|
||||
- (NSString *) accessibilityValue;
|
||||
@end
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* GS_API_MACOSX */
|
||||
|
||||
#endif /* _NSAccessibilityProtocols_h_GNUSTEP_GUI_INCLUDE */
|
||||
|
|
@ -123,6 +123,18 @@ enum {
|
|||
};
|
||||
typedef NSUInteger NSCellStateValue;
|
||||
|
||||
#if OS_API_VERSION(MAC_OS_X_VERSION_10_13, GS_API_LATEST)
|
||||
/*
|
||||
* Control state values as of 10.13
|
||||
*/
|
||||
enum {
|
||||
NSControlStateValueMixed = -1,
|
||||
NSControlStateValueOff = 0,
|
||||
NSControlStateValueOn = 1
|
||||
};
|
||||
typedef NSUInteger NSControlStateValue;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* <p>Enumeration of the ways that you can display an image in an
|
||||
* NSImageCell. The available ones are:</p>
|
||||
|
|
58
Headers/AppKit/NSSwitch.h
Normal file
58
Headers/AppKit/NSSwitch.h
Normal file
|
@ -0,0 +1,58 @@
|
|||
/* Definition of class NSSwitch
|
||||
Copyright (C) 2020 Free Software Foundation, Inc.
|
||||
|
||||
By: Gregory John Casamento
|
||||
Date: Wed Apr 8 22:01:02 EDT 2020
|
||||
|
||||
This file is part of the GNUstep 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.1 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; if not, write to the Free
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110 USA.
|
||||
*/
|
||||
|
||||
#ifndef _NSSwitch_h_GNUSTEP_GUI_INCLUDE
|
||||
#define _NSSwitch_h_GNUSTEP_GUI_INCLUDE
|
||||
|
||||
#import <AppKit/NSControl.h>
|
||||
#import <AppKit/NSCell.h>
|
||||
#import <AppKit/NSAccessibilityProtocols.h>
|
||||
|
||||
#if OS_API_VERSION(MAC_OS_X_VERSION_10_15, GS_API_LATEST)
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
@interface NSSwitch : NSControl <NSAccessibilitySwitch>
|
||||
{
|
||||
NSControlStateValue _state;
|
||||
id _target;
|
||||
SEL _action;
|
||||
BOOL _enabled;
|
||||
}
|
||||
|
||||
- (void) setState: (NSControlStateValue)s;
|
||||
- (NSControlStateValue) state;
|
||||
|
||||
@end
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* GS_API_MACOSX */
|
||||
|
||||
#endif /* _NSSwitch_h_GNUSTEP_GUI_INCLUDE */
|
||||
|
2
MISSING
2
MISSING
|
@ -4,7 +4,6 @@ MISSING HEADERS
|
|||
> NSAccessibilityCustomAction.h
|
||||
> NSAccessibilityCustomRotor.h
|
||||
> NSAccessibilityElement.h
|
||||
> NSAccessibilityProtocols.h
|
||||
> NSCollectionViewCompositionalLayout.h
|
||||
> NSCollectionViewFlowLayout.h
|
||||
> NSCollectionViewGridLayout.h
|
||||
|
@ -34,7 +33,6 @@ MISSING HEADERS
|
|||
> NSStatusBarButton.h
|
||||
> NSStoryboard.h
|
||||
> NSStoryboardSegue.h
|
||||
> NSSwitch.h
|
||||
> NSTabViewController.h
|
||||
> NSTableCellView.h
|
||||
> NSTableRowView.h
|
||||
|
|
|
@ -122,6 +122,7 @@ NSRotationGestureRecognizer.m \
|
|||
NSSharingServicePickerTouchBarItem.m \
|
||||
NSSliderTouchBarItem.m \
|
||||
NSStepperTouchBarItem.m \
|
||||
NSSwitch.m \
|
||||
NSTouch.m \
|
||||
NSTouchBar.m \
|
||||
NSTouchBarItem.m \
|
||||
|
@ -351,6 +352,7 @@ AppKitErrors.h \
|
|||
AppKitExceptions.h \
|
||||
NSAccessibility.h \
|
||||
NSAccessibilityConstants.h \
|
||||
NSAccessibilityProtocols.h \
|
||||
NSActionCell.h \
|
||||
NSAffineTransform.h \
|
||||
NSAlert.h \
|
||||
|
@ -506,6 +508,7 @@ NSStepperTouchBarItem.h \
|
|||
NSStringDrawing.h \
|
||||
NSStatusBar.h \
|
||||
NSStatusItem.h \
|
||||
NSSwitch.h \
|
||||
NSTabView.h \
|
||||
NSTabViewItem.h \
|
||||
NSTableColumn.h \
|
||||
|
|
|
@ -816,6 +816,139 @@
|
|||
[self drawStepperDownButton: downRect];
|
||||
}
|
||||
|
||||
// NSSwitch drawing methods
|
||||
|
||||
- (void) drawSwitchBezel: (NSRect)frame
|
||||
forState: (NSControlStateValue)v
|
||||
enabled: (BOOL)enabled
|
||||
{
|
||||
NSBezierPath *p;
|
||||
NSPoint point;
|
||||
CGFloat radius;
|
||||
NSColor *backgroundColor;
|
||||
|
||||
if (enabled == NO)
|
||||
{
|
||||
backgroundColor = [NSColor disabledControlTextColor];
|
||||
}
|
||||
else if (NSControlStateValueOn != v)
|
||||
{
|
||||
backgroundColor = [NSColor windowBackgroundColor]; // offColor
|
||||
}
|
||||
else
|
||||
{
|
||||
backgroundColor = [NSColor selectedControlColor]; // onColor
|
||||
}
|
||||
|
||||
// make smaller than enclosing frame
|
||||
frame = NSInsetRect(frame, 4, 4);
|
||||
radius = frame.size.height / 2.0;
|
||||
point = frame.origin;
|
||||
point.x += radius;
|
||||
point.y += radius - 0.5;
|
||||
|
||||
// Draw initial path to enclose the button...
|
||||
// left half-circle
|
||||
p = [NSBezierPath bezierPath];
|
||||
[p appendBezierPathWithArcWithCenter: point
|
||||
radius: radius
|
||||
startAngle: 90.0
|
||||
endAngle: 270.0];
|
||||
|
||||
// line to first point and right halfcircle
|
||||
point.x += frame.size.width - frame.size.height;
|
||||
[p appendBezierPathWithArcWithCenter: point
|
||||
radius: radius
|
||||
startAngle: 270.0
|
||||
endAngle: 90.0];
|
||||
[p closePath];
|
||||
|
||||
// fill with background color
|
||||
[backgroundColor set];
|
||||
[p fill];
|
||||
|
||||
// and stroke rounded button
|
||||
[[NSColor shadowColor] set];
|
||||
[p stroke];
|
||||
|
||||
// Add highlights...
|
||||
point = frame.origin;
|
||||
point.x += radius - 0.5;
|
||||
point.y += radius - 0.5;
|
||||
p = [NSBezierPath bezierPath];
|
||||
[p setLineWidth: 1.0];
|
||||
[p appendBezierPathWithArcWithCenter: point
|
||||
radius: radius
|
||||
startAngle: 135.0
|
||||
endAngle: 270.0];
|
||||
|
||||
// line to first point and right halfcircle
|
||||
point.x += frame.size.width - frame.size.height;
|
||||
[p appendBezierPathWithArcWithCenter: point
|
||||
radius: radius
|
||||
startAngle: 270.0
|
||||
endAngle: 315.0];
|
||||
[[NSColor controlLightHighlightColor] set];
|
||||
[p stroke];
|
||||
}
|
||||
|
||||
- (void) drawSwitchKnob: (NSRect)frame
|
||||
forState: (NSControlStateValue)value
|
||||
enabled: (BOOL)enabled
|
||||
{
|
||||
NSColor *backgroundColor = enabled ? [NSColor windowBackgroundColor] : [NSColor disabledControlTextColor];
|
||||
NSBezierPath *oval;
|
||||
NSRect rect = NSZeroRect;
|
||||
CGFloat w = (frame.size.width / 2) - 2;
|
||||
CGFloat h = frame.size.height - 6;
|
||||
CGFloat y = frame.origin.y + 2;
|
||||
CGFloat radius = frame.size.height / 2.0;
|
||||
|
||||
[backgroundColor set];
|
||||
if (value == NSControlStateValueOff)
|
||||
{
|
||||
rect = NSMakeRect(frame.origin.x + 4,
|
||||
y,
|
||||
w,
|
||||
h);
|
||||
}
|
||||
else
|
||||
{
|
||||
rect = NSMakeRect(frame.origin.x + ((frame.size.width - 2 * radius) + 2), // ((frame.size.width - w) - 2)
|
||||
y,
|
||||
w,
|
||||
h);
|
||||
}
|
||||
|
||||
|
||||
oval = [NSBezierPath bezierPathWithOvalInRect: NSInsetRect(rect, 1, 1)];
|
||||
|
||||
// fill oval with background color
|
||||
[backgroundColor set];
|
||||
[oval fill];
|
||||
|
||||
// and stroke rounded button
|
||||
[[NSColor shadowColor] set];
|
||||
[oval stroke];
|
||||
}
|
||||
|
||||
|
||||
- (void) drawSwitchInRect: (NSRect)rect
|
||||
forState: (NSControlStateValue)state
|
||||
enabled: (BOOL)enabled
|
||||
{
|
||||
// Draw the well bezel
|
||||
[self drawSwitchBezel: rect
|
||||
forState: state
|
||||
enabled: enabled];
|
||||
|
||||
// Draw the knob
|
||||
[self drawSwitchKnob: rect
|
||||
forState: state
|
||||
enabled: enabled];
|
||||
|
||||
}
|
||||
|
||||
// NSSegmentedControl drawing methods
|
||||
|
||||
- (void) drawSegmentedControlSegment: (NSCell *)cell
|
||||
|
|
|
@ -381,7 +381,8 @@ static NSArray *XmlBoolDefaultYes = nil;
|
|||
@"decodeDividerStyleForElement:", @"NSDividerStyle",
|
||||
@"decodeToolbarIdentifiedItemsForElement:", @"NSToolbarIBIdentifiedItems",
|
||||
@"decodeToolbarImageForElement:", @"NSToolbarItemImage",
|
||||
nil];
|
||||
@"decodeControlContentsForElement:", @"NSControlContents",
|
||||
nil];
|
||||
RETAIN(XmlKeyToDecoderSelectorMap);
|
||||
|
||||
// boolean fields that should be treated as YES when missing.
|
||||
|
@ -390,6 +391,7 @@ static NSArray *XmlBoolDefaultYes = nil;
|
|||
@"bordered",
|
||||
@"prefersToBeShown",
|
||||
@"editable",
|
||||
@"enabled",
|
||||
nil];
|
||||
}
|
||||
}
|
||||
|
@ -2725,6 +2727,19 @@ didStartElement: (NSString*)elementName
|
|||
return [self findResourceWithName: name];
|
||||
}
|
||||
|
||||
- (id) decodeControlContentsForElement: (GSXibElement *)element
|
||||
{
|
||||
NSNumber *num = [NSNumber numberWithInteger: 0];
|
||||
id obj = [element attributeForKey: @"state"];
|
||||
|
||||
if ([obj isEqualToString: @"on"])
|
||||
{
|
||||
num = [NSNumber numberWithInteger: 1];
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
- (id) objectForXib: (GSXibElement*)element
|
||||
{
|
||||
id object = [super objectForXib: element];
|
||||
|
@ -2788,7 +2803,6 @@ didStartElement: (NSString*)elementName
|
|||
else if ([object respondsToSelector: @selector(setHeaderToolTip:)])
|
||||
[object setHeaderToolTip: [element attributeForKey: @"toolTip"]];
|
||||
}
|
||||
|
||||
// Process IB runtime attributes for element...
|
||||
// Ensure we don't process the placeholders...
|
||||
if ([element elementForKey: @"userDefinedRuntimeAttributes"] &&
|
||||
|
@ -3153,6 +3167,10 @@ didStartElement: (NSString*)elementName
|
|||
hasValue = [currentElement attributeForKey: @"title"] != nil;
|
||||
hasValue |= [currentElement attributeForKey: @"image"] != nil;
|
||||
}
|
||||
else if ([@"NSControlContents" isEqualToString: key])
|
||||
{
|
||||
hasValue = [currentElement attributeForKey: @"state"] != nil;
|
||||
}
|
||||
else if ([@"NSAlternateContents" isEqualToString: key])
|
||||
{
|
||||
hasValue = [currentElement attributeForKey: @"alternateTitle"] != nil;
|
||||
|
|
|
@ -899,7 +899,7 @@ systemColorWithName(NSString *name)
|
|||
return systemColorWithName(@"toolTipTextColor");
|
||||
}
|
||||
|
||||
+ (NSColor *)windowBackgroundColor
|
||||
+ (NSColor *) windowBackgroundColor
|
||||
{
|
||||
return systemColorWithName(@"windowBackgroundColor");
|
||||
}
|
||||
|
|
|
@ -130,12 +130,6 @@ typedef struct {
|
|||
NSInteger height;
|
||||
} MRect;
|
||||
|
||||
static inline MPoint MakePoint (NSInteger x, NSInteger y)
|
||||
{
|
||||
MPoint point = { x, y };
|
||||
return point;
|
||||
}
|
||||
|
||||
@interface NSMatrix (PrivateMethods)
|
||||
- (void) _renewRows: (NSInteger)row
|
||||
columns: (NSInteger)col
|
||||
|
|
291
Source/NSSwitch.m
Normal file
291
Source/NSSwitch.m
Normal file
|
@ -0,0 +1,291 @@
|
|||
/* Implementation of class NSSwitch
|
||||
Copyright (C) 2020 Free Software Foundation, Inc.
|
||||
|
||||
By: Gregory John Casamento
|
||||
Date: Wed Apr 8 22:01:02 EDT 2020
|
||||
|
||||
This file is part of the GNUstep 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.1 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; if not, write to the Free
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110 USA.
|
||||
*/
|
||||
|
||||
#import "AppKit/NSSwitch.h"
|
||||
#import "GNUstepGUI/GSTheme.h"
|
||||
|
||||
@implementation NSSwitch
|
||||
|
||||
+ (void) initialize
|
||||
{
|
||||
if (self == [NSSwitch class])
|
||||
{
|
||||
[self setVersion: 1];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) setState: (NSControlStateValue)s
|
||||
{
|
||||
_state = s;
|
||||
[self setNeedsDisplay];
|
||||
}
|
||||
|
||||
- (NSControlStateValue) state
|
||||
{
|
||||
return _state;
|
||||
}
|
||||
|
||||
- (void) setAction: (SEL)action
|
||||
{
|
||||
_action = action;
|
||||
}
|
||||
|
||||
- (SEL) action
|
||||
{
|
||||
return _action;
|
||||
}
|
||||
|
||||
- (void) setTarget: (id)target
|
||||
{
|
||||
_target = target;
|
||||
}
|
||||
|
||||
- (id) target
|
||||
{
|
||||
return _target;
|
||||
}
|
||||
|
||||
- (void) setEnabled: (BOOL)flag
|
||||
{
|
||||
_enabled = flag;
|
||||
[self setNeedsDisplay];
|
||||
}
|
||||
|
||||
- (BOOL) isEnabled
|
||||
{
|
||||
return _enabled;
|
||||
}
|
||||
|
||||
- (void) setDoubleValue: (double)val
|
||||
{
|
||||
if (val < 1.0)
|
||||
{
|
||||
[self setState: NSControlStateValueOff];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self setState: NSControlStateValueOn];
|
||||
}
|
||||
}
|
||||
|
||||
- (double) doubleValue
|
||||
{
|
||||
return (double)(([self state] == NSControlStateValueOn) ? 1.0 : 0.0);
|
||||
}
|
||||
|
||||
- (void) setFloatValue: (float)val
|
||||
{
|
||||
[self setDoubleValue: (double)val];
|
||||
}
|
||||
|
||||
- (float) floatValue
|
||||
{
|
||||
return (float)[self doubleValue];
|
||||
}
|
||||
|
||||
- (void) setIntValue: (int)val
|
||||
{
|
||||
[self setDoubleValue: (double)val];
|
||||
}
|
||||
|
||||
- (int) intValue
|
||||
{
|
||||
return (int)[self doubleValue];
|
||||
}
|
||||
|
||||
- (void) setIntegerValue: (NSInteger)val
|
||||
{
|
||||
[self setDoubleValue: (double)val];
|
||||
}
|
||||
|
||||
- (NSInteger) integerValue
|
||||
{
|
||||
return (NSInteger)[self doubleValue];
|
||||
}
|
||||
|
||||
- (void) setStringValue: (NSString *)val
|
||||
{
|
||||
[self setDoubleValue: [val doubleValue]];
|
||||
}
|
||||
|
||||
- (NSString *) stringValue
|
||||
{
|
||||
return [NSString stringWithFormat: @"%ld", [self integerValue]];
|
||||
}
|
||||
|
||||
- (void) setObjectValue: (id)obj
|
||||
{
|
||||
if ([obj respondsToSelector: @selector(stringValue)])
|
||||
{
|
||||
[self setStringValue: [obj stringValue]];
|
||||
}
|
||||
}
|
||||
|
||||
- (id) objectValue
|
||||
{
|
||||
return [self stringValue];
|
||||
}
|
||||
|
||||
- (void) drawRect: (NSRect)rect
|
||||
{
|
||||
[[GSTheme theme] drawSwitchInRect: rect
|
||||
forState: _state
|
||||
enabled: [self isEnabled]];
|
||||
}
|
||||
|
||||
- (void) mouseDown: (NSEvent *)event
|
||||
{
|
||||
if (![self isEnabled])
|
||||
{
|
||||
[super mouseDown: event];
|
||||
return;
|
||||
}
|
||||
|
||||
if (_state == NSControlStateValueOn)
|
||||
{
|
||||
[self setState: NSControlStateValueOff];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self setState: NSControlStateValueOn];
|
||||
}
|
||||
|
||||
if (_action)
|
||||
{
|
||||
[self sendAction: _action
|
||||
to: _target];
|
||||
}
|
||||
}
|
||||
|
||||
// Accessibility
|
||||
- (NSRect)accessibilityFrame
|
||||
{
|
||||
return [self frame];
|
||||
}
|
||||
|
||||
- (NSString *)accessibilityIdentifier
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (id)accessibilityParent
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (BOOL)isAccessibilityFocused
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (NSString *)accessibilityLabel
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (BOOL)accessibilityPerformPress
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL) accessibilityPerformDecrement
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL) accessibilityPerformIncrement
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (NSString *) accessibilityValue
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
// NSCoding
|
||||
- (id) initWithCoder: (NSCoder *)coder
|
||||
{
|
||||
if ((self = [super initWithCoder: coder]) != nil)
|
||||
{
|
||||
if ([coder allowsKeyedCoding])
|
||||
{
|
||||
if ([coder containsValueForKey: @"NSControlContents"])
|
||||
{
|
||||
[self setState: [coder decodeIntegerForKey: @"NSControlContents"]];
|
||||
}
|
||||
if ([coder containsValueForKey: @"NSControlAction"])
|
||||
{
|
||||
NSString *s = [coder decodeObjectForKey: @"NSControlAction"];
|
||||
[self setAction: NSSelectorFromString(s)];
|
||||
}
|
||||
if ([coder containsValueForKey: @"NSControlTarget"])
|
||||
{
|
||||
id t = [coder decodeObjectForKey: @"NSControlTarget"];
|
||||
[self setTarget: t];
|
||||
}
|
||||
if ([coder containsValueForKey: @"NSEnabled"])
|
||||
{
|
||||
BOOL e = [coder decodeBoolForKey: @"NSEnabled"];
|
||||
|
||||
// NSControl decodes this, but does not use the value which
|
||||
// is decoded. See comment in NSControl.m initWithCoder:.
|
||||
[self setEnabled: e];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
[coder decodeValueOfObjCType: @encode(NSInteger)
|
||||
at: &_state];
|
||||
[self setAction: NSSelectorFromString((NSString *)[coder decodeObject])];
|
||||
[self setTarget: [coder decodeObject]];
|
||||
}
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) encodeWithCoder: (NSCoder *)coder
|
||||
{
|
||||
[super encodeWithCoder: coder];
|
||||
if ([coder allowsKeyedCoding])
|
||||
{
|
||||
[coder encodeInteger: _state
|
||||
forKey: @"NSControlContents"];
|
||||
[coder encodeObject: NSStringFromSelector(_action)
|
||||
forKey: @"NSControlAction"];
|
||||
[coder encodeObject: _target
|
||||
forKey: @"NSControlTarget"];
|
||||
}
|
||||
else
|
||||
{
|
||||
[coder encodeValueOfObjCType: @encode(NSInteger)
|
||||
at: &_state];
|
||||
[coder encodeObject: NSStringFromSelector([self action])];
|
||||
[coder encodeObject: [self target]];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -84,7 +84,7 @@ typedef enum {
|
|||
static const int ItemBackViewX = 0;
|
||||
static const int ItemBackViewY = 0;
|
||||
static const int InsetItemViewX = 10;
|
||||
static const int InsetItemViewY = 26;
|
||||
// static const int InsetItemViewY = 26;
|
||||
static const int InsetItemTextX = 3;
|
||||
static const int InsetItemTextY = 4;
|
||||
|
||||
|
|
Loading…
Reference in a new issue