Skip to content

Commit

Permalink
#366, implement NSButton setButtonType: in terms of NSButtonCell setB…
Browse files Browse the repository at this point in the history
…uttonType:, add more NSButtonCell API

git-svn-id: http://cocotron.googlecode.com/svn/trunk@613 43251c19-cd1f-0410-9ec0-95c558c233a8
  • Loading branch information
cocotron committed Aug 24, 2009
1 parent cb9f3c5 commit 9c1b53e
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 24 deletions.
5 changes: 3 additions & 2 deletions AppKit/NSButton.m
Expand Up @@ -24,7 +24,7 @@ -(BOOL)resignFirstResponder {
}

-(BOOL)isOpaque {
return ![_cell isTransparent] && [_cell isBordered];
return [_cell isOpaque];
}

-(BOOL)isTransparent {
Expand Down Expand Up @@ -168,7 +168,8 @@ -(void)setShowsBorderOnlyWhileMouseInside:(BOOL)value {
}

-(void)setButtonType:(NSButtonType)value {
NSUnimplementedMethod();
[_cell setButtonType:value];
[self setNeedsDisplay:YES];
}

-(void)setTitleWithMnemonic:(NSString *)value {
Expand Down
74 changes: 53 additions & 21 deletions AppKit/NSButtonCell.h
Expand Up @@ -7,6 +7,7 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */

#import <AppKit/NSActionCell.h>
#import <AppKit/NSImageCell.h>

@class NSSound;

Expand All @@ -19,33 +20,41 @@ enum {
};

typedef enum {
NSMomentaryLightButton,
NSPushOnPushOffButton,
NSToggleButton,
NSSwitchButton,
NSRadioButton,
NSMomentaryChangeButton,
NSOnOffButton,
NSMomentaryPushInButton,
NSMomentaryLightButton=0,
NSPushOnPushOffButton=1,
NSToggleButton=2,
NSSwitchButton=3,
NSRadioButton=4,
NSMomentaryChangeButton=5,
NSOnOffButton=6,
NSMomentaryPushInButton=7,
} NSButtonType;

typedef enum {
NSRoundedBezelStyle=1,
NSRegularSquareBezelStyle,
NSThickSquareBezelStyle,
NSThickerSquareBezelStyle,
NSDisclosureBezelStyle,
NSShadowlessSquareBezelStyle,
NSCircularBezelStyle,
NSTexturedSquareBezelStyle,
NSHelpButtonBezelStyle,
NSSmallSquareBezelStyle,
NSTexturedRoundedBezelStyle,
NSRoundRectBezelStyle,
NSRecessedBezelStyle,
NSRoundedDisclosureBezelStyle,
NSRegularSquareBezelStyle=2,
NSThickSquareBezelStyle=3,
NSThickerSquareBezelStyle=4,
NSDisclosureBezelStyle=5,
NSShadowlessSquareBezelStyle=6,
NSCircularBezelStyle=7,
NSTexturedSquareBezelStyle=8,
NSHelpButtonBezelStyle=9,
NSSmallSquareBezelStyle=10,
NSTexturedRoundedBezelStyle=11,
NSRoundRectBezelStyle=12,
NSRecessedBezelStyle=13,
NSRoundedDisclosureBezelStyle=14,
} NSBezelStyle;

typedef enum {
NSGradientNone =0,
NSGradientConcaveWeak =1,
NSGradientConcaveStrong=2,
NSGradientConvexWeak =3,
NSGradientConvexStrong =4,
} NSGradientType;

@interface NSButtonCell : NSActionCell {
NSString *_alternateTitle;
NSImage *_alternateImage;
Expand All @@ -59,6 +68,11 @@ typedef enum {
unsigned _keyEquivalentModifierMask;
BOOL _showsBorderOnlyWhileMouseInside;
NSSound *_sound;
NSGradientType _gradientType;
NSImageScaling _imageScaling;
NSFont *_keyEquivalentFont;
NSColor *_backgroundColor;
float _periodicDelay,_periodicInterval;
}

-(BOOL)isTransparent;
Expand All @@ -76,6 +90,12 @@ typedef enum {
-(NSBezelStyle)bezelStyle;
-(BOOL)showsBorderOnlyWhileMouseInside;
-(NSSound *)sound;
-(NSGradientType)gradientType;
-(NSImageScaling)imageScaling;
-(BOOL)isOpaque;
-(NSFont *)keyEquivalentFont;
-(NSColor *)backgroundColor;
-(void)getPeriodicDelay:(float *)delay interval:(float *)interval;

-(void)setTransparent:(BOOL)flag;
-(void)setKeyEquivalent:(NSString *)keyEquivalent;
Expand All @@ -93,8 +113,20 @@ typedef enum {
-(void)setButtonType:(NSButtonType)buttonType;
-(void)setShowsBorderOnlyWhileMouseInside:(BOOL)show;
-(void)setSound:(NSSound *)sound;
-(void)setGradientType:(NSGradientType)value;
-(void)setBackgroundColor:(NSColor *)value;
-(void)setImageScaling:(NSImageScaling)value;
-(void)setKeyEquivalentFont:(NSFont *)value;
-(void)setKeyEquivalentFont:(NSString *)value size:(CGFloat)size;
-(void)setPeriodicDelay:(float)delay interval:(float)interval;

-(void)performClick:sender;

-(void)drawBezelWithFrame:(NSRect)rect inView:(NSView *)view;
-(void)drawImage:(NSImage *)image withFrame:(NSRect)rect inView:(NSView *)view;

-(void)mouseEntered:(NSEvent *)event;
-(void)mouseExited:(NSEvent *)event;

@end

79 changes: 78 additions & 1 deletion AppKit/NSButtonCell.m
Expand Up @@ -149,6 +149,9 @@ -(void)dealloc {
[_alternateTitle release];
[_alternateImage release];
[_keyEquivalent release];
[_sound release];
[_keyEquivalentFont release];
[_backgroundColor release];
[super dealloc];
}

Expand All @@ -158,7 +161,10 @@ -(void)dealloc {
result->_alternateTitle =[_alternateTitle copy];
result->_alternateImage=[_alternateImage retain];
result->_keyEquivalent=[_keyEquivalent copy];

result->_sound=[_sound retain];
result->_keyEquivalentFont=[_keyEquivalentFont retain];
result->_backgroundColor=[_backgroundColor retain];

return result;
}

Expand Down Expand Up @@ -268,6 +274,31 @@ -(NSSound *)sound {
return _sound;
}

-(NSGradientType)gradientType {
return _gradientType;
}

-(NSImageScaling)imageScaling {
return _imageScaling;
}

-(BOOL)isOpaque {
return ![self isTransparent] && [self isBordered];
}

-(NSFont *)keyEquivalentFont {
return _keyEquivalentFont;
}

-(NSColor *)backgroundColor {
return _backgroundColor;
}

-(void)getPeriodicDelay:(float *)delay interval:(float *)interval {
*delay=_periodicDelay;
*interval=_periodicInterval;
}

-(int)state {
return [self intValue];
}
Expand Down Expand Up @@ -432,6 +463,36 @@ -(void)setSound:(NSSound *)sound {
_sound=sound;
}

-(void)setGradientType:(NSGradientType)value {
_gradientType=value;
}

-(void)setBackgroundColor:(NSColor *)value {
value=[value copy];
[_backgroundColor release];
_backgroundColor=value;
}

-(void)setImageScaling:(NSImageScaling)value {
_imageScaling=value;
}

-(void)setKeyEquivalentFont:(NSFont *)value {
value=[value retain];
[_keyEquivalentFont release];
_keyEquivalentFont=value;
}

-(void)setKeyEquivalentFont:(NSString *)value size:(CGFloat)size {
NSFont *font=[NSFont fontWithName:value size:size];
[self setKeyEquivalentFont:font];
}

-(void)setPeriodicDelay:(float)delay interval:(float)interval {
_periodicDelay=delay;
_periodicInterval=interval;
}

-(NSAttributedString *)titleForHighlight {
if((([self highlightsBy]&NSContentsCellMask) && [self isHighlighted]) ||
(([self showsStateBy]&NSContentsCellMask) && [self state])){
Expand Down Expand Up @@ -470,6 +531,14 @@ -(BOOL)isVisuallyHighlighted {
(([self showsStateBy]&NSChangeGrayCellMask) && [self state]));
}

-(void)drawBezelWithFrame:(NSRect)rect inView:(NSView *)view {
NSUnimplementedMethod();
}

-(void)drawImage:(NSImage *)image withFrame:(NSRect)rect inView:(NSView *)view {
NSUnimplementedMethod();
}

-(void)drawInteriorWithFrame:(NSRect)frame inView:(NSView *)controlView {
NSAttributedString *title=[self titleForHighlight];
NSImage *image=[self imageForHighlight];
Expand Down Expand Up @@ -725,4 +794,12 @@ -(void)performClick:sender {
[_controlView performSelector:@selector(performClick:) withObject:sender];
}

-(void)mouseEntered:(NSEvent *)event {
NSUnimplementedMethod();
}

-(void)mouseExited:(NSEvent *)event {
NSUnimplementedMethod();
}

@end

0 comments on commit 9c1b53e

Please sign in to comment.