- NSAlert implemented

- NSButton expanded to match doc.s, NSCell, NSButtonCell attributedTitle work
This commit is contained in:
Christopher Lloyd 2008-05-13 18:43:48 +00:00
parent 8de0df5a30
commit e64bcd2609
12 changed files with 521 additions and 86 deletions

View File

@ -63,7 +63,7 @@ static BOOL initFunctionsForParameters(KGImage *self,size_t bitsPerComponent,siz
}
}
break;
case 8:
switch(bitsPerPixel){

View File

@ -8,24 +8,37 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#import <Foundation/NSObject.h>
@class NSButton,NSImage,NSArray,NSWindow,NSError;
@class NSButton,NSImage,NSArray,NSWindow,NSError,NSView,NSMutableArray;
typedef enum {
NSWarningAlertStyle,
NSInformationalAlertStyle,
NSCriticalAlertStyle
NSCriticalAlertStyle,
} NSAlertStyle;
enum {
NSAlertFirstButtonReturn=1000,
NSAlertSecondButtonReturn=1001,
NSAlertThirdButtonReturn=1002,
};
@interface NSAlert : NSObject {
id _delegate;
NSAlertStyle _style;
NSImage *_icon;
NSString *_messageText;
NSString *_informativeText;
NSView *_accessoryView;
BOOL _showsHelp;
BOOL _showsSuppressionButton;
NSString *_helpAnchor;
NSArray *_buttons;
NSMutableArray *_buttons;
NSButton *_supressionButton;
NSWindow *_window;
BOOL _needsLayout;
id _sheetDelegate;
SEL _sheetDidEnd;
}
+(NSAlert *)alertWithError:(NSError *)error;
@ -36,23 +49,30 @@ typedef enum {
-(NSImage *)icon;
-(NSString *)messageText;
-(NSString *)informativeText;
-(NSView *)accessoryView;
-(BOOL)showsHelp;
-(BOOL)showsSuppressionButton;
-(NSString *)helpAnchor;
-(NSArray *)buttons;
-(NSButton *)supressionButton;
-window;
-(void)setDelegate:delegate;
-(void)setAlertStyle:(NSAlertStyle)style;
-(void)setIcon:(NSImage *)icon;
-(void)setMessageText:(NSString *)string;
-(void)setInformativeText:(NSString *)string;
-(void)setShowsHelp:(BOOL)flag;
-(void)setHelpAnchor:(NSString *)anchor;
-(void)setAlertStyle:(NSAlertStyle)value;
-(void)setIcon:(NSImage *)value;
-(void)setMessageText:(NSString *)value;
-(void)setInformativeText:(NSString *)value;
-(void)setAccessoryView:(NSView *)value;
-(void)setShowsHelp:(BOOL)value;
-(void)setShowsSuppressionButton:(BOOL)value;
-(void)setHelpAnchor:(NSString *)value;
-(NSButton *)addButtonWithTitle:(NSString *)title;
-(void)layout;
-(void)beginSheetModalForWindow:(NSWindow *)window modalDelegate:delegate didEndSelector:(SEL)selector contextInfo:(void *)info;
-(int)runModal;
-(NSInteger)runModal;
@end

View File

@ -9,19 +9,97 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#import <AppKit/NSAlert.h>
#import <AppKit/NSImage.h>
#import <Foundation/NSRaise.h>
#import <Foundation/NSDictionary.h>
#import <AppKit/NSStringDrawer.h>
#import <AppKit/NSButton.h>
#import <AppKit/NSScreen.h>
#import <AppKit/NSApplication.h>
#import <AppKit/NSPanel.h>
#import <AppKit/NSWindow-Private.h>
#import <AppKit/NSImageView.h>
#import <AppKit/NSTextField.h>
#import <AppKit/NSFont.h>
#import <AppKit/NSAttributedString.h>
@implementation NSAlert
/*
NSWarningAlertStyle - app icon
NSInformationalAlertStyle - app icon
NSCriticalAlertStyle - large yellow /!\ triangle w/ small app icon
*/
-init {
_style=NSWarningAlertStyle;
_icon=[[NSImage imageNamed:@"NSAlertPanelExclamation"] retain];
_messageText=[NSLocalizedString(@"Alert",@"Default message text for NSAlert") copy];
_informativeText=@"";
_accessoryView=nil;
_showsHelp=NO;
_showsSuppressionButton=NO;
_helpAnchor=nil;
_buttons=[NSMutableArray new];
_window=[[NSPanel alloc] initWithContentRect:NSMakeRect(0,0,10,10) styleMask:NSTitledWindowMask backing:NSBackingStoreBuffered defer:NO];
_supressionButton=[[NSButton alloc] init];
// [_supressionButton setButtonType:NSSwitchButton];
[_supressionButton setTitle:NSLocalizedString(@"Do not show this message again",@"Default NSAlert supression button title")];
_needsLayout=YES;
return self;
}
-(void)dealloc {
[_icon release];
[_messageText release];
[_informativeText release];
[_accessoryView release];
[_helpAnchor release];
[_buttons release];
[_supressionButton release];
[_window release];
[super dealloc];
}
+(NSAlert *)alertWithError:(NSError *)error {
NSUnimplementedMethod();
return nil;
NSArray *titles=[error localizedRecoveryOptions];
NSString *defaultTitle=([titles count]>0)?[titles objectAtIndex:0]:nil;
NSString *alternateTitle=([titles count]>1)?[titles objectAtIndex:1]:nil;
NSString *otherTitle=([titles count]>2)?[titles objectAtIndex:2]:nil;
NSAlert *result=[[[self alloc] init] autorelease];
[result setMessageText:[error localizedDescription]];
[result setInformativeText:[error localizedRecoverySuggestion]];
int i,count=[titles count];
for(i=0;i<count;i++)
[result addButtonWithTitle:[titles objectAtIndex:i]];
return result;
}
+(NSAlert *)alertWithMessageText:(NSString *)messageText defaultButton:(NSString *)defaultTitle alternateButton:(NSString *)alternateTitle otherButton:(NSString *)otherTitle informativeTextWithFormat:(NSString *)format,... {
NSUnimplementedMethod();
return nil;
va_list arguments;
NSString *informativeText;
va_start(arguments,format);
informativeText=[[[NSString alloc] initWithFormat:format arguments:arguments] autorelease];
NSAlert *result=[[[self alloc] init] autorelease];
[result setMessageText:messageText];
[result setInformativeText:informativeText];
if(defaultTitle==nil)
defaultTitle=NSLocalizedString(@"OK",@"Default button title for NSAlert");
[result addButtonWithTitle:defaultTitle];
if(alternateTitle!=nil)
[result addButtonWithTitle:alternateTitle];
if(otherTitle!=nil)
[result addButtonWithTitle:otherTitle];
return result;
}
-delegate {
return _delegate;
}
@ -42,10 +120,18 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
return _informativeText;
}
-(NSView *)accessoryView {
return _accessoryView;
}
-(BOOL)showsHelp {
return _showsHelp;
}
-(BOOL)showsSuppressionButton {
return _showsSuppressionButton;
}
-(NSString *)helpAnchor {
return _helpAnchor;
}
@ -54,6 +140,10 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
return _buttons;
}
-(NSButton *)supressionButton {
return _supressionButton;
}
-window {
return _window;
}
@ -64,48 +154,265 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
-(void)setAlertStyle:(NSAlertStyle)style {
_style=style;
_needsLayout=YES;
}
-(void)setIcon:(NSImage *)icon {
icon=[icon copy];
[_icon release];
_icon=icon;
_needsLayout=YES;
}
-(void)setMessageText:(NSString *)string {
string=[string copy];
[_messageText release];
_messageText=string;
_needsLayout=YES;
}
-(void)setInformativeText:(NSString *)string {
string=[string copy];
[_informativeText release];
_informativeText=string;
_needsLayout=YES;
}
-(void)setAccessoryView:(NSView *)value {
value=[value retain];
[_accessoryView release];
_accessoryView=value;
_needsLayout=YES;
}
-(void)setShowsHelp:(BOOL)flag {
_showsHelp=flag;
_needsLayout=YES;
}
-(void)setShowsSuppressionButton:(BOOL)value {
_showsSuppressionButton=value;
_needsLayout=YES;
}
-(void)setHelpAnchor:(NSString *)anchor {
anchor=[anchor copy];
[_helpAnchor release];
_helpAnchor=anchor;
_needsLayout=YES;
}
-(NSButton *)addButtonWithTitle:(NSString *)title {
NSUnimplementedMethod();
return nil;
NSButton *result=[[NSButton alloc] init];
[result setTitle:title];
[result setTarget:self];
[result setAction:@selector(_alertButton:)];
[result setTag:NSAlertFirstButtonReturn+[_buttons count]];
[_buttons addObject:result];
_needsLayout=YES;
return result;
}
-(void)layout {
#define MAINSIZE_MINWIDTH 100
#define BOTTOM_MARGIN 16
#define TOP_MARGIN 16
#define LEFT_MARGIN 16
#define RIGHT_MARGIN 16
#define ICON_MARGIN 8
#define TEXT_MARGIN 8
#define BUTTON_MARGIN 8
#define INTERBUTTON_GAP 6
#define OTHER_GAP 20
#define ICON_MAIN_GAP 20
#define MAIN_BUTTON_GAP 20
NSSize drawSize={[[NSScreen mainScreen] visibleFrame].size.width/3,INT_MAX};
NSStringDrawer *drawer=[[[NSStringDrawer alloc] initWithSize:drawSize] autorelease];
NSSize iconSize=(_icon!=nil)?[_icon size]:NSZeroSize;
NSDictionary *messageAttributes=[NSDictionary dictionaryWithObjectsAndKeys:[NSFont boldSystemFontOfSize:0],NSFontAttributeName,nil];
NSSize messageSize=(_messageText!=nil)?[drawer sizeOfString:_messageText withAttributes:messageAttributes]:NSZeroSize;
NSDictionary *informativeAttributes=[NSDictionary dictionaryWithObjectsAndKeys:[NSFont systemFontOfSize:0],NSFontAttributeName,nil];
NSSize informativeSize=(_informativeText!=nil)?[drawer sizeOfString:_informativeText withAttributes:informativeAttributes]:NSZeroSize;
NSDictionary *suppressionAttributes=[NSDictionary dictionaryWithObjectsAndKeys:[NSFont systemFontOfSize:0],NSFontAttributeName,nil];
NSSize supressionSize=(_showsSuppressionButton)?[drawer sizeOfString:[_supressionButton title] withAttributes:suppressionAttributes]:NSZeroSize;
NSSize accessorySize=(_accessoryView!=nil)?[_accessoryView frame].size:NSZeroSize;
NSSize okCancelMaxSize={40,24};
NSSize otherMaxSize={40,24};
NSSize mainSize=NSZeroSize;
NSSize panelSize=NSZeroSize;
NSSize allButtonsSize=NSZeroSize;
int i,count=[_buttons count];
for(i=0;i<count && i<2;i++){
NSButton *check=[_buttons objectAtIndex:i];
NSAttributedString *title=[check attributedTitle];
NSSize size=[drawer sizeOfAttributedString:title];
okCancelMaxSize.width=MAX(size.width,okCancelMaxSize.width);
okCancelMaxSize.height=MAX(size.height,okCancelMaxSize.height);
}
okCancelMaxSize.width+=BUTTON_MARGIN*2;
for(i=0;i<count && i<2;i++)
[[_buttons objectAtIndex:i] setFrameSize:okCancelMaxSize];
for(i=2;i<count;i++){
NSButton *check=[_buttons objectAtIndex:i];
NSAttributedString *title=[check attributedTitle];
NSSize size=[drawer sizeOfAttributedString:title];
otherMaxSize.width=MAX(size.width,otherMaxSize.width);
otherMaxSize.height=MAX(size.height,otherMaxSize.height);
}
otherMaxSize.width+=BUTTON_MARGIN*2;
for(i=0;i<count && i<2;i++)
[[_buttons objectAtIndex:i] setFrameSize:otherMaxSize];
for(i=0;i<count;i++){
NSButton *button=[_buttons objectAtIndex:i];
allButtonsSize.width+=[button frame].size.width;
allButtonsSize.height=MAX(allButtonsSize.height,[button frame].size.height);
allButtonsSize.width+=INTERBUTTON_GAP;
if(i==1)
allButtonsSize.width+=OTHER_GAP;
}
mainSize.width=MAX(messageSize.width,MAX(informativeSize.width,MAX(supressionSize.width,accessorySize.width)))+TEXT_MARGIN*2;
mainSize.width=MAX(MAINSIZE_MINWIDTH,mainSize.width);
mainSize.height=messageSize.height+informativeSize.height+supressionSize.height+accessorySize.height+TEXT_MARGIN*2;
panelSize.width=LEFT_MARGIN+MAX(iconSize.width+ICON_MAIN_GAP+mainSize.width,allButtonsSize.width)+RIGHT_MARGIN;
panelSize.height=TOP_MARGIN+MAX(mainSize.height,iconSize.height)+MAIN_BUTTON_GAP+allButtonsSize.height+BOTTOM_MARGIN;
if(_icon!=nil){
NSRect frame;
NSImageView *imageView;
frame.origin.x=LEFT_MARGIN;
frame.origin.y=panelSize.height-TOP_MARGIN-iconSize.height;
frame.size=iconSize;
imageView=[[[NSImageView alloc] initWithFrame:frame] autorelease];
[imageView setImage:_icon];
[[_window contentView] addSubview:imageView];
}
if(_messageText!=nil){
NSRect frame;
NSTextField *textField;
frame.origin.x=LEFT_MARGIN+iconSize.width+ICON_MAIN_GAP;
frame.origin.y=panelSize.height-TOP_MARGIN-messageSize.height;
frame.size=messageSize;
frame.size.width+=TEXT_MARGIN*2;
textField=[[[NSTextField alloc] initWithFrame:frame] autorelease];
[textField setAttributedStringValue:[[[NSAttributedString alloc] initWithString:_messageText attributes:messageAttributes] autorelease]];
[textField setSelectable:YES];
[textField setBordered:NO];
[[_window contentView] addSubview:textField];
}
if(_informativeText!=nil){
NSRect frame;
NSTextField *textField;
frame.origin.x=LEFT_MARGIN+iconSize.width+ICON_MAIN_GAP;
frame.origin.y=panelSize.height-TOP_MARGIN-messageSize.height-informativeSize.height;
frame.size=informativeSize;
textField=[[[NSTextField alloc] initWithFrame:frame] autorelease];
[textField setStringValue:[[[NSAttributedString alloc] initWithString:_informativeText attributes:informativeAttributes] autorelease]];
[textField setSelectable:YES];
[textField setBordered:NO];
[[_window contentView] addSubview:textField];
}
if(_showsSuppressionButton){
NSRect frame;
frame.origin.x=LEFT_MARGIN+iconSize.width+ICON_MAIN_GAP;
frame.origin.y=panelSize.height-TOP_MARGIN-messageSize.height-informativeSize.height-frame.size.height;
frame.size=supressionSize;
[_supressionButton setFrame:frame];
[[_window contentView] addSubview:_supressionButton];
}
if(_accessoryView!=nil){
NSRect frame=[_accessoryView frame];
frame.origin.x=LEFT_MARGIN+iconSize.width+ICON_MAIN_GAP;
frame.origin.y=panelSize.height-TOP_MARGIN-messageSize.height-informativeSize.height-supressionSize.height-frame.size.height;
[_accessoryView setFrame:frame];
[[_window contentView] addSubview:_accessoryView];
}
NSPoint origin={panelSize.width-RIGHT_MARGIN,BOTTOM_MARGIN};
for(i=0;i<count;i++){
NSButton *button=[_buttons objectAtIndex:i];
NSSize bSize=[button frame].size;
origin.x-=bSize.width;
[button setFrameOrigin:origin];
origin.x-=INTERBUTTON_GAP;
if(i==1)
origin.x-=OTHER_GAP;
[[_window contentView] addSubview:button];
}
NSRect contentRect={{0,0},panelSize};
NSRect frame=[_window frameRectForContentRect:contentRect];
[_window setFrame:frame display:NO];
_needsLayout=NO;
}
-(void)layoutIfNeeded {
// This isn't an optimization per se, it is to prevent relayout after a manual layout
if(_needsLayout){
if([_buttons count]==0){
[self addButtonWithTitle:NSLocalizedString(@"OK",@"Default button title for NSAlert")];
}
[self layout];
}
}
-(void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo {
typedef void (*alertDidEnd)(id,SEL,NSAlert *,int,void *);
alertDidEnd endFunction=(alertDidEnd)[_sheetDelegate methodForSelector:_sheetDidEnd];
endFunction(_sheetDelegate,_sheetDidEnd,self,returnCode,contextInfo);
}
-(void)beginSheetModalForWindow:(NSWindow *)window modalDelegate:delegate didEndSelector:(SEL)selector contextInfo:(void *)info {
NSUnimplementedMethod();
[_window _setStyleMask:NSDocModalWindowMask];
[self layoutIfNeeded];
_sheetDelegate=delegate;
_sheetDidEnd=selector;
[NSApp beginSheet:_window modalForWindow:window modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) contextInfo:info];
}
-(int)runModal {
NSUnimplementedMethod();
return 0;
-(NSInteger)runModal {
[_window _setStyleMask:NSTitledWindowMask];
[self layoutIfNeeded];
return [NSApp runModalForWindow:_window];
}
-(void)_alertButton:sender {
if([_window isSheet])
[NSApp endSheet:_window returnCode:[sender tag]];
else
[NSApp stopModalWithCode:[sender tag]];
[_window close];
}
@end

View File

@ -688,11 +688,12 @@ id NSApp=nil;
-(void)beginSheet:(NSWindow *)sheet modalForWindow:(NSWindow *)window modalDelegate:modalDelegate didEndSelector:(SEL)didEndSelector contextInfo:(void *)contextInfo {
NSSheetContext *context=[NSSheetContext sheetContextWithSheet:sheet modalDelegate:modalDelegate didEndSelector:didEndSelector contextInfo:contextInfo frame:[sheet frame]];
// // Hmmm
#if 1
// Hmmmm, is this correct?
if ([sheet styleMask] != NSDocModalWindowMask)
[sheet _setStyleMask:NSDocModalWindowMask];
#endif
// if ([sheet styleMask] != NSBorderlessWindowMask)
// [sheet _setStyleMask:NSBorderlessWindowMask];

View File

@ -13,23 +13,46 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
-(BOOL)isTransparent;
-(NSString *)keyEquivalent;
-(NSUInteger)keyEquivalentModifierMask;
-(NSImage *)image;
-(NSCellImagePosition)imagePosition;
-(NSString *)title;
-(int)state;
-(NSInteger)state;
-(BOOL)allowsMixedState;
-(NSSound *)sound;
-(void)setTransparent:(BOOL)flag;
-(void)setKeyEquivalent:(NSString *)keyEquivalent;
-(void)setImage:(NSImage *)image;
-(void)setImagePosition:(NSCellImagePosition)position;
-(void)setTitle:(NSString *)title;
-(void)setState:(int)value;
-(void)setNextState;
-(void)setAllowsMixedState:(BOOL)flag;
-(void)setSound:(NSSound *)sound;
-(NSBezelStyle)bezelStyle;
-(NSString *)alternateTitle;
-(NSImage *)alternateImage;
-(NSAttributedString *)attributedTitle;
-(NSAttributedString *)attributedAlternateTitle;
-(BOOL)showsBorderOnlyWhileMouseInside;
-(void)getPeriodicDelay:(float *)delay interval:(float *)interval;
-(void)setTransparent:(BOOL)value;
-(void)setKeyEquivalent:(NSString *)value;
-(void)setKeyEquivalentModifierMask:(NSUInteger)value;
-(void)setImage:(NSImage *)value;
-(void)setImagePosition:(NSCellImagePosition)value;
-(void)setTitle:(NSString *)value;
-(void)setState:(NSInteger)value;
-(void)setNextState;
-(void)setAllowsMixedState:(BOOL)value;
-(void)setSound:(NSSound *)value;
-(void)setBezelStyle:(NSBezelStyle)value;
-(void)setAlternateTitle:(NSString *)value;
-(void)setAlternateImage:(NSImage *)value;
-(void)setAttributedTitle:(NSAttributedString *)value;
-(void)setAttributedAlternateTitle:(NSAttributedString *)value;
-(void)setShowsBorderOnlyWhileMouseInside:(BOOL)value;
-(void)setPeriodicDelay:(float)delay interval:(float)interval;
-(void)setButtonType:(NSButtonType)value;
-(void)setTitleWithMnemonic:(NSString *)value;
-(void)highlight:(BOOL)value;
-(BOOL)performKeyEquivalent:(NSEvent *)event;
-(void)performClick:sender;
@end

View File

@ -35,6 +35,10 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
return [_cell keyEquivalent];
}
-(NSUInteger)keyEquivalentModifierMask {
return [_cell keyEquivalentModifierMask];
}
-(NSImage *)image {
return [_cell image];
}
@ -47,7 +51,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
return [_cell title];
}
-(int)state {
-(NSInteger)state {
return [_cell state];
}
@ -59,31 +63,63 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
return [_cell sound];
}
-(void)setTransparent:(BOOL)flag {
[_cell setTransparent:flag];
-(NSBezelStyle)bezelStyle {
return [_cell bezelStyle];
}
-(NSString *)alternateTitle {
return [_cell alternateTitle];
}
-(NSImage *)alternateImage {
return [_cell alternateImage];
}
-(NSAttributedString *)attributedTitle {
return [_cell attributedTitle];
}
-(NSAttributedString *)attributedAlternateTitle {
return [_cell attributedAlternateTitle];
}
-(BOOL)showsBorderOnlyWhileMouseInside {
return [_cell showsBorderOnlyWhileMouseInside];
}
-(void)getPeriodicDelay:(float *)delay interval:(float *)interval {
NSUnimplementedMethod();
}
-(void)setTransparent:(BOOL)value {
[_cell setTransparent:value];
[self setNeedsDisplay:YES];
}
-(void)setKeyEquivalent:(NSString *)keyEquivalent {
[_cell setKeyEquivalent:keyEquivalent];
-(void)setKeyEquivalent:(NSString *)value {
[_cell setKeyEquivalent:value];
}
-(void)setImage:(NSImage *)image {
[_cell setImage:image];
-(void)setKeyEquivalentModifierMask:(NSUInteger)value {
[_cell setKeyEquivalentModifierMask:value];
}
-(void)setImage:(NSImage *)value {
[_cell setImage:value];
[self setNeedsDisplay:YES];
}
-(void)setImagePosition:(NSCellImagePosition)position {
[_cell setImagePosition:position];
-(void)setImagePosition:(NSCellImagePosition)value {
[_cell setImagePosition:value];
[self setNeedsDisplay:YES];
}
-(void)setTitle:(NSString *)title {
[_cell setTitle:title];
-(void)setTitle:(NSString *)value {
[_cell setTitle:value];
[self setNeedsDisplay:YES];
}
-(void)setState:(int)value {
-(void)setState:(NSInteger)value {
[_cell setState:value];
[self setNeedsDisplay:YES];
}
@ -101,12 +137,53 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
[_cell setSound:sound];
}
-(unsigned)keyEquivalentModifierMask {
return [_cell keyEquivalentModifierMask];
-(void)setBezelStyle:(NSBezelStyle)value {
[_cell setBezelStyle:value];
[self setNeedsDisplay:YES];
}
-(void)setKeyEquivalentModifierMask:(unsigned)mask {
[_cell setKeyEquivalentModifierMask:mask];
-(void)setAlternateTitle:(NSString *)value {
[_cell setAlternateTitle:value];
[self setNeedsDisplay:YES];
}
-(void)setAlternateImage:(NSImage *)value {
[_cell setAlternateImage:value];
[self setNeedsDisplay:YES];
}
-(void)setAttributedTitle:(NSAttributedString *)value {
[_cell setAttributedTitle:value];
[self setNeedsDisplay:YES];
}
-(void)setAttributedAlternateTitle:(NSAttributedString *)value {
[_cell setAttributedAlternateTitle:value];
[self setNeedsDisplay:YES];
}
-(void)setShowsBorderOnlyWhileMouseInside:(BOOL)value {
[_cell setShowsBorderOnlyWhileMouseInside:value];
[self setNeedsDisplay:YES];
}
-(void)setButtonType:(NSButtonType)value {
NSUnimplementedMethod();
}
-(void)setTitleWithMnemonic:(NSString *)value {
NSUnimplementedMethod();
}
-(void)setPeriodicDelay:(float)delay interval:(float)interval {
NSUnimplementedMethod();
}
-(void)highlight:(BOOL)value {
[self lockFocus];
[_cell highlight:value withFrame:[self bounds] inView:self];
[self unlockFocus];
[[self window] flushWindow];
}
-(BOOL)performKeyEquivalent:(NSEvent *)event {
@ -129,19 +206,13 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
}
-(void)performClick:sender {
[self lockFocus];
[_cell highlight:YES withFrame:[self bounds] inView:self];
[self unlockFocus];
[[self window] flushWindow];
[self highlight:YES];
[[self cell] setState:[[self cell] nextState]];
[self sendAction:[self action] to:[self target]];
[self lockFocus];
[_cell highlight:NO withFrame:[self bounds] inView:self];
[self unlockFocus];
[[self window] flushWindow];
[self highlight:NO];
}
-(void)keyDown:(NSEvent *)event {

View File

@ -6,7 +6,6 @@ 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. */
// Original - Christopher Lloyd <cjwl@objc.net>
#import <AppKit/NSButtonCell.h>
#import <AppKit/NSApplication.h>
#import <AppKit/NSGraphics.h>
@ -31,7 +30,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
-(void)encodeWithCoder:(NSCoder *)coder {
[super encodeWithCoder:coder];
[coder encodeObject:_title forKey:@"NSButtonCell title"];
[coder encodeObject:_titleOrAttributedTitle forKey:@"NSButtonCell title"];
[coder encodeObject:_alternateTitle forKey:@"NSButtonCell alternateTitle"];
[coder encodeInt:_imagePosition forKey:@"NSButtonCell imagePosition"];
[coder encodeInt:_highlightsBy forKey:@"NSButtonCell highlightsBy"];
@ -52,7 +51,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
unsigned flags2=[keyed decodeIntForKey:@"NSButtonFlags2"];
id check;
_title=[[keyed decodeObjectForKey:@"NSContents"] retain];
_titleOrAttributedTitle=[[keyed decodeObjectForKey:@"NSContents"] retain];
_alternateTitle=[[keyed decodeObjectForKey:@"NSAlternateContents"] retain];
_imagePosition=NSNoImage;
@ -174,7 +173,10 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
}
-(NSString *)title {
return _title;
if([_titleOrAttributedTitle isKindOfClass:[NSAttributedString class]])
return [_titleOrAttributedTitle string];
else
return _titleOrAttributedTitle;
}
-(NSString *)alternateTitle {
@ -186,26 +188,30 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
}
-(NSAttributedString *)attributedTitle {
NSMutableDictionary *attributes=[NSMutableDictionary dictionary];
NSMutableParagraphStyle *paraStyle=[[[NSParagraphStyle defaultParagraphStyle] mutableCopy] autorelease];
NSFont *font=[self font];
if([_titleOrAttributedTitle isKindOfClass:[NSAttributedString class]])
return _titleOrAttributedTitle;
else {
NSMutableDictionary *attributes=[NSMutableDictionary dictionary];
NSMutableParagraphStyle *paraStyle=[[[NSParagraphStyle defaultParagraphStyle] mutableCopy] autorelease];
NSFont *font=[self font];
if(font!=nil)
[attributes setObject:font forKey:NSFontAttributeName];
if(font!=nil)
[attributes setObject:font forKey:NSFontAttributeName];
if(![self wraps])
[paraStyle setLineBreakMode:NSLineBreakByClipping];
[paraStyle setAlignment:_textAlignment];
[attributes setObject:paraStyle forKey:NSParagraphStyleAttributeName];
if(![self wraps])
[paraStyle setLineBreakMode:NSLineBreakByClipping];
[paraStyle setAlignment:_textAlignment];
[attributes setObject:paraStyle forKey:NSParagraphStyleAttributeName];
if([self isEnabled])
[attributes setObject:[NSColor controlTextColor]
if([self isEnabled])
[attributes setObject:[NSColor controlTextColor]
forKey:NSForegroundColorAttributeName];
else
[attributes setObject:[NSColor disabledControlTextColor]
else
[attributes setObject:[NSColor disabledControlTextColor]
forKey:NSForegroundColorAttributeName];
return [[[NSAttributedString alloc] initWithString:[self title] attributes:attributes] autorelease];
return [[[NSAttributedString alloc] initWithString:_titleOrAttributedTitle attributes:attributes] autorelease];
}
}
-(NSAttributedString *)attributedAlternateTitle {
@ -280,8 +286,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
-(void)setTitle:(NSString *)title {
title=[title copy];
[_title release];
_title=title;
[_titleOrAttributedTitle release];
_titleOrAttributedTitle=title;
}
-(void)setAlternateTitle:(NSString *)title {
@ -297,7 +303,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
}
-(void)setAttributedTitle:(NSAttributedString *)title {
NSUnimplementedMethod();
title=[title copy];
[_titleOrAttributedTitle release];
_titleOrAttributedTitle=title;
}
-(void)setAttributedAlternateTitle:(NSAttributedString *)title {

View File

@ -61,7 +61,7 @@ typedef NSUInteger NSControlTint;
NSWritingDirection _writingDirection;
int _cellType;
NSFormatter *_formatter;
NSString *_title;
id _titleOrAttributedTitle;
id _representedObject;
NSControlSize _controlSize;

View File

@ -124,7 +124,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
[_objectValue release];
[_image release];
[_formatter release];
[_title release];
[_titleOrAttributedTitle release];
[_representedObject release];
[super dealloc];
}
@ -136,7 +136,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
copy->_objectValue=[_objectValue copy];
copy->_image=[_image retain];
copy->_formatter=[_formatter retain];
copy->_title=[_title retain];
copy->_titleOrAttributedTitle=[_titleOrAttributedTitle copy];
copy->_representedObject=[_representedObject retain];
return copy;
@ -204,7 +204,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
}
-(NSString *)title {
return _title;
return _titleOrAttributedTitle;
}
-(BOOL)isEnabled {
@ -440,8 +440,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
-(void)setTitle:(NSString *)title {
title = [title retain];
[_title release];
_title = title;
[_titleOrAttributedTitle release];
_titleOrAttributedTitle = title;
}
-(void)setEnabled:(BOOL)flag {

View File

@ -71,6 +71,7 @@ APPKIT_EXPORT NSString *NSControlTextDidEndEditingNotification;
-(void)setIntValue:(int)value;
-(void)setFloatValue:(float)value;
-(void)setDoubleValue:(double)value;
-(void)setAttributedStringValue:(NSAttributedString *)value;
-(void)takeObjectValueFrom:sender;
-(void)takeStringValueFrom:sender;

View File

@ -254,6 +254,10 @@ static NSMutableDictionary *cellClassDictionary = nil;
[self setObjectValue:[NSNumber numberWithDouble:value]];
}
-(void)setAttributedStringValue:(NSAttributedString *)value {
[self setObjectValue:value];
}
-(void)takeObjectValueFrom:sender {
[self setObjectValue:[sender objectValue]];
}

View File

@ -8,7 +8,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#import <Foundation/NSObject.h>
#import <Foundation/NSArray.h>
@class NSDictionary;
@class NSDictionary,NSSet;
FOUNDATION_EXPORT NSString *const NSKeyValueChangeKindKey;
FOUNDATION_EXPORT NSString *const NSKeyValueChangeNewKey;