mirror of
https://github.com/darlinghq/darling-cocotron.git
synced 2024-11-23 12:09:51 +00:00
Original
This commit is contained in:
parent
675207edce
commit
30916ff6e5
110
AppKit/AppKit.h
Executable file
110
AppKit/AppKit.h
Executable file
@ -0,0 +1,110 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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 <Foundation/Foundation.h>
|
||||
|
||||
#import <AppKit/NSActionCell.h>
|
||||
#import <AppKit/NSAffineTransform.h>
|
||||
#import <AppKit/NSApplication.h>
|
||||
#import <AppKit/NSAttributedString.h>
|
||||
#import <AppKit/NSBitmapImageRep.h>
|
||||
#import <AppKit/NSBox.h>
|
||||
#import <AppKit/NSButton.h>
|
||||
#import <AppKit/NSButtonCell.h>
|
||||
#import <AppKit/NSBrowser.h>
|
||||
#import <AppKit/NSBrowserCell.h>
|
||||
#import <AppKit/NSCachedImageRep.h>
|
||||
#import <AppKit/NSCell.h>
|
||||
#import <AppKit/NSClipView.h>
|
||||
#import <AppKit/NSColor.h>
|
||||
#import <AppKit/NSColorList.h>
|
||||
#import <AppKit/NSColorPanel.h>
|
||||
#import <AppKit/NSColorPicker.h>
|
||||
#import <AppKit/NSColorWell.h>
|
||||
#import <AppKit/NSComboBox.h>
|
||||
#import <AppKit/NSComboBoxCell.h>
|
||||
#import <AppKit/NSControl.h>
|
||||
#import <AppKit/NSCursor.h>
|
||||
#import <AppKit/NSCustomImageRep.h>
|
||||
#import <AppKit/NSDocument.h>
|
||||
#import <AppKit/NSDocumentController.h>
|
||||
#import <AppKit/NSDragging.h>
|
||||
#import <AppKit/NSDrawer.h>
|
||||
#import <AppKit/NSEPSImageRep.h>
|
||||
#import <AppKit/NSEvent.h>
|
||||
#import <AppKit/NSFileWrapper.h>
|
||||
#import <AppKit/NSFont.h>
|
||||
#import <AppKit/NSFontManager.h>
|
||||
#import <AppKit/NSFontPanel.h>
|
||||
#import <AppKit/NSForm.h>
|
||||
#import <AppKit/NSFormCell.h>
|
||||
#import <AppKit/NSGraphics.h>
|
||||
#import <AppKit/NSGraphicsContext.h>
|
||||
#import <AppKit/NSImage.h>
|
||||
#import <AppKit/NSImageCell.h>
|
||||
#import <AppKit/NSImageRep.h>
|
||||
#import <AppKit/NSInterfaceStyle.h>
|
||||
#import <AppKit/NSLayoutManager.h>
|
||||
#import <AppKit/NSMatrix.h>
|
||||
#import <AppKit/NSMenu.h>
|
||||
#import <AppKit/NSMenuItem.h>
|
||||
#import <AppKit/NSMutableParagraphStyle.h>
|
||||
#import <AppKit/NSNibLoading.h>
|
||||
#import <AppKit/NSNibConnector.h>
|
||||
#import <AppKit/NSNibControlConnector.h>
|
||||
#import <AppKit/NSNibOutletConnector.h>
|
||||
#import <AppKit/NSOpenPanel.h>
|
||||
#import <AppKit/NSOutlineView.h>
|
||||
#import <AppKit/NSPageLayout.h>
|
||||
#import <AppKit/NSPanel.h>
|
||||
#import <AppKit/NSParagraphStyle.h>
|
||||
#import <AppKit/NSPasteboard.h>
|
||||
#import <AppKit/NSPopUpButton.h>
|
||||
#import <AppKit/NSPopUpButtonCell.h>
|
||||
#import <AppKit/NSPrintOperation.h>
|
||||
#import <AppKit/NSPrintInfo.h>
|
||||
#import <AppKit/NSProgressIndicator.h>
|
||||
#import <AppKit/NSResponder.h>
|
||||
#import <AppKit/NSRulerMarker.h>
|
||||
#import <AppKit/NSRulerView.h>
|
||||
#import <AppKit/NSSavePanel.h>
|
||||
#import <AppKit/NSScreen.h>
|
||||
#import <AppKit/NSScroller.h>
|
||||
#import <AppKit/NSScrollView.h>
|
||||
#import <AppKit/NSSlider.h>
|
||||
#import <AppKit/NSSliderCell.h>
|
||||
#import <AppKit/NSSplitView.h>
|
||||
#import <AppKit/NSStepper.h>
|
||||
#import <AppKit/NSStepperCell.h>
|
||||
#import <AppKit/NSStringDrawing.h>
|
||||
#import <AppKit/NSSecureTextField.h>
|
||||
#import <AppKit/NSSecureTextFieldCell.h>
|
||||
#import <AppKit/NSTableColumn.h>
|
||||
#import <AppKit/NSTableHeaderCell.h>
|
||||
#import <AppKit/NSTableHeaderView.h>
|
||||
#import <AppKit/NSTableView.h>
|
||||
#import <AppKit/NSTabView.h>
|
||||
#import <AppKit/NSTabViewItem.h>
|
||||
#import <AppKit/NSText.h>
|
||||
#import <AppKit/NSTextAttachment.h>
|
||||
#import <AppKit/NSTextContainer.h>
|
||||
#import <AppKit/NSTextField.h>
|
||||
#import <AppKit/NSTextFieldCell.h>
|
||||
#import <AppKit/NSTextStorage.h>
|
||||
#import <AppKit/NSTextTab.h>
|
||||
#import <AppKit/NSTextView.h>
|
||||
#import <AppKit/NSToolbar.h>
|
||||
#import <AppKit/NSToolbarItem.h>
|
||||
#import <AppKit/NSView.h>
|
||||
#import <AppKit/NSWindow.h>
|
||||
#import <AppKit/NSWindowController.h>
|
||||
#import <AppKit/NSWorkspace.h>
|
||||
|
||||
#import <AppKit/CoreGraphics.h>
|
||||
|
||||
#define IBOutlet
|
2467
AppKit/AppKit.xcodeproj/project.pbxproj
Normal file
2467
AppKit/AppKit.xcodeproj/project.pbxproj
Normal file
File diff suppressed because it is too large
Load Diff
15
AppKit/AppKitExport.h
Executable file
15
AppKit/AppKitExport.h
Executable file
@ -0,0 +1,15 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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. */
|
||||
|
||||
#if defined(__WIN32__)
|
||||
#if defined(APPKIT_INSIDE_BUILD)
|
||||
#define APPKIT_EXPORT __declspec(dllexport) extern
|
||||
#else
|
||||
#define APPKIT_EXPORT __declspec(dllimport) extern
|
||||
#endif
|
||||
#endif
|
40
AppKit/CoreGraphics.subproj/CGAffineTransform.h
Executable file
40
AppKit/CoreGraphics.subproj/CGAffineTransform.h
Executable file
@ -0,0 +1,40 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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 <Foundation/Foundation.h>
|
||||
#import <AppKit/AppKitExport.h>
|
||||
|
||||
#import <AppKit/CGGeometry.h>
|
||||
|
||||
typedef struct {
|
||||
float a;
|
||||
float b;
|
||||
float c;
|
||||
float d;
|
||||
float tx;
|
||||
float ty;
|
||||
} CGAffineTransform;
|
||||
|
||||
APPKIT_EXPORT const CGAffineTransform CGAffineTransformIdentity;
|
||||
|
||||
APPKIT_EXPORT CGAffineTransform CGAffineTransformMake(float a,float b,float c,float d,float tx,float ty);
|
||||
APPKIT_EXPORT CGAffineTransform CGAffineTransformMakeRotation(float radians);
|
||||
APPKIT_EXPORT CGAffineTransform CGAffineTransformMakeScale(float scalex,float scaley);
|
||||
APPKIT_EXPORT CGAffineTransform CGAffineTransformMakeTranslation(float tx,float ty);
|
||||
|
||||
APPKIT_EXPORT CGAffineTransform CGAffineTransformConcat(CGAffineTransform xform,CGAffineTransform append);
|
||||
APPKIT_EXPORT CGAffineTransform CGAffineTransformInvert(CGAffineTransform xform);
|
||||
|
||||
APPKIT_EXPORT CGAffineTransform CGAffineTransformRotate(CGAffineTransform xform,float radians);
|
||||
APPKIT_EXPORT CGAffineTransform CGAffineTransformScale(CGAffineTransform xform,float scalex,float scaley);
|
||||
APPKIT_EXPORT CGAffineTransform CGAffineTransformTranslate(CGAffineTransform xform,float tx,float ty);
|
||||
|
||||
APPKIT_EXPORT CGPoint CGPointApplyAffineTransform(CGPoint point, CGAffineTransform xform);
|
||||
APPKIT_EXPORT CGSize CGSizeApplyAffineTransform(CGSize size, CGAffineTransform xform);
|
||||
|
||||
|
96
AppKit/CoreGraphics.subproj/CGAffineTransform.m
Executable file
96
AppKit/CoreGraphics.subproj/CGAffineTransform.m
Executable file
@ -0,0 +1,96 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/CGAffineTransform.h>
|
||||
|
||||
const CGAffineTransform CGAffineTransformIdentity={1,0,0,1,0,0};
|
||||
|
||||
CGAffineTransform CGAffineTransformMake(float a,float b,float c,float d,float tx,float ty){
|
||||
CGAffineTransform xform={a,b,c,d,tx,ty};
|
||||
return xform;
|
||||
}
|
||||
|
||||
CGAffineTransform CGAffineTransformMakeRotation(float radians){
|
||||
CGAffineTransform xform={cos(radians),sin(radians),-sin(radians),cos(radians),0,0};
|
||||
return xform;
|
||||
}
|
||||
|
||||
CGAffineTransform CGAffineTransformMakeScale(float scalex,float scaley){
|
||||
CGAffineTransform xform={scalex,0,0,scaley,0,0};
|
||||
return xform;
|
||||
}
|
||||
|
||||
CGAffineTransform CGAffineTransformMakeTranslation(float tx,float ty){
|
||||
CGAffineTransform xform={1,0,0,1,tx,ty};
|
||||
return xform;
|
||||
}
|
||||
|
||||
CGAffineTransform CGAffineTransformConcat(CGAffineTransform xform,CGAffineTransform append){
|
||||
CGAffineTransform result;
|
||||
|
||||
result.a=append.a*xform.a+append.b*xform.c;
|
||||
result.b=append.a*xform.b+append.b*xform.d;
|
||||
result.c=append.c*xform.a+append.d*xform.c;
|
||||
result.d=append.c*xform.b+append.d*xform.d;
|
||||
result.tx=append.tx*xform.a+append.ty*xform.c+xform.tx;
|
||||
result.ty=append.tx*xform.b+append.ty*xform.d+xform.ty;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
CGAffineTransform CGAffineTransformInvert(CGAffineTransform xform){
|
||||
CGAffineTransform result;
|
||||
float determinant;
|
||||
|
||||
determinant=xform.a*xform.d-xform.c*xform.b;
|
||||
if(determinant==0)
|
||||
return xform;
|
||||
|
||||
result.a=xform.d/determinant;
|
||||
result.b=-xform.b/determinant;
|
||||
result.c=-xform.c/determinant;
|
||||
result.d=xform.a/determinant;
|
||||
result.tx=(-xform.d*xform.tx+xform.c*xform.ty)/determinant;
|
||||
result.ty=(xform.b*xform.tx-xform.a*xform.ty)/determinant;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
CGAffineTransform CGAffineTransformRotate(CGAffineTransform xform,float radians){
|
||||
CGAffineTransform rotate=CGAffineTransformMakeRotation(radians);
|
||||
return CGAffineTransformConcat(xform,rotate);
|
||||
}
|
||||
|
||||
CGAffineTransform CGAffineTransformScale(CGAffineTransform xform,float scalex,float scaley){
|
||||
CGAffineTransform scale=CGAffineTransformMakeScale(scalex,scaley);
|
||||
return CGAffineTransformConcat(xform,scale);
|
||||
}
|
||||
|
||||
CGAffineTransform CGAffineTransformTranslate(CGAffineTransform xform,float tx,float ty){
|
||||
CGAffineTransform translate=CGAffineTransformMakeTranslation(tx,ty);
|
||||
return CGAffineTransformConcat(xform,translate);
|
||||
}
|
||||
|
||||
CGPoint CGPointApplyAffineTransform(CGPoint point,CGAffineTransform xform){
|
||||
CGPoint p;
|
||||
|
||||
p.x=xform.a*point.x+xform.c*point.y+xform.tx;
|
||||
p.y=xform.b*point.x+xform.d*point.y+xform.ty;
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
CGSize CGSizeApplyAffineTransform(CGSize size,CGAffineTransform xform){
|
||||
CGSize s;
|
||||
|
||||
s.width=xform.a*size.width+xform.c*size.height;
|
||||
s.height=xform.b*size.width+xform.d*size.height;
|
||||
|
||||
return s;
|
||||
}
|
85
AppKit/CoreGraphics.subproj/CGContext.h
Executable file
85
AppKit/CoreGraphics.subproj/CGContext.h
Executable file
@ -0,0 +1,85 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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 <Foundation/Foundation.h>
|
||||
#import <AppKit/CGFont.h>
|
||||
#import <AppKit/CGGeometry.h>
|
||||
#import <AppKit/CGAffineTransform.h>
|
||||
#import <AppKit/AppKitExport.h>
|
||||
|
||||
@class CGRenderingContext;
|
||||
|
||||
@interface CGContext : NSObject
|
||||
|
||||
@end
|
||||
|
||||
typedef enum {
|
||||
kCGEncodingFontSpecific
|
||||
} CGTextEncoding;
|
||||
|
||||
typedef CGContext *CGContextRef;
|
||||
|
||||
APPKIT_EXPORT void CGContextSaveGState(CGContextRef context);
|
||||
APPKIT_EXPORT void CGContextRestoreGState(CGContextRef context);
|
||||
|
||||
APPKIT_EXPORT CGAffineTransform CGContextGetCTM(CGContextRef context);
|
||||
APPKIT_EXPORT void CGContextConcatCTM(CGContextRef context,CGAffineTransform transform);
|
||||
APPKIT_EXPORT void CGContextTranslateCTM(CGContextRef context,float translatex,float translatey);
|
||||
APPKIT_EXPORT void CGContextScaleCTM(CGContextRef context,float scalex,float scaley);
|
||||
APPKIT_EXPORT void CGContextRotateCTM(CGContextRef context,float radians);
|
||||
|
||||
APPKIT_EXPORT CGAffineTransform CGContextGetTextMatrix(CGContextRef context);
|
||||
APPKIT_EXPORT void CGContextSetTextMatrix(CGContextRef context, CGAffineTransform transform);
|
||||
|
||||
APPKIT_EXPORT void CGContextClipToRect(CGContextRef context,CGRect rect);
|
||||
APPKIT_EXPORT void CGContextClipToRects(CGContextRef context,const CGRect *rects,unsigned count);
|
||||
|
||||
APPKIT_EXPORT void CGContextBeginPath(CGContextRef context);
|
||||
APPKIT_EXPORT void CGContextClosePath(CGContextRef context);
|
||||
APPKIT_EXPORT void CGContextMoveToPoint(CGContextRef context,float x,float y);
|
||||
APPKIT_EXPORT void CGContextAddLineToPoint(CGContextRef context,float x,float y);
|
||||
APPKIT_EXPORT void CGContextAddArc(CGContextRef context,float x,float y,float radius,float startRadian,float endRadian,int clockwise);
|
||||
APPKIT_EXPORT void CGContextAddArcToPoint(CGContextRef context,float x1,float y1,float x2,float y2,float radius);
|
||||
APPKIT_EXPORT void CGContextAddCurveToPoint(CGContextRef context,float cx1,float cy1,float cx2,float cy2,float x,float y);
|
||||
|
||||
APPKIT_EXPORT void CGContextFillPath(CGContextRef context);
|
||||
APPKIT_EXPORT void CGContextFillRect(CGContextRef context,CGRect rect);
|
||||
APPKIT_EXPORT void CGContextFillRects(CGContextRef context,const CGRect *rects,unsigned count);
|
||||
|
||||
APPKIT_EXPORT void CGContextSetLineWidth(CGContextRef context,float width);
|
||||
|
||||
APPKIT_EXPORT void CGContextStrokePath(CGContextRef context);
|
||||
APPKIT_EXPORT void CGContextStrokeRect(CGContextRef context,CGRect rect);
|
||||
APPKIT_EXPORT void CGContextStrokeRectWithWidth(CGContextRef context,CGRect rect,float width);
|
||||
|
||||
APPKIT_EXPORT void CGContextSelectFont(CGContextRef context,const char *name,float size,CGTextEncoding encoding);
|
||||
APPKIT_EXPORT void CGContextShowTextAtPoint(CGContextRef context,float x,float y,const char *text,unsigned count);
|
||||
APPKIT_EXPORT void CGContextShowGlyphsAtPoint(CGContextRef context,float x,float y,const CGGlyph *glyphs,unsigned count);
|
||||
APPKIT_EXPORT void CGContextShowGlyphsWithAdvances(CGContextRef context,const CGGlyph *glyphs,const CGSize *advances,unsigned count);
|
||||
|
||||
APPKIT_EXPORT void CGContextBeginPage(CGContextRef context,const CGRect *mediaBox);
|
||||
APPKIT_EXPORT void CGContextEndPage(CGContextRef context);
|
||||
|
||||
// Temporary hacks
|
||||
|
||||
APPKIT_EXPORT void CGContextSetDeviceGrayColor(CGContextRef context,float gray,float alpha);
|
||||
APPKIT_EXPORT void CGContextSetDeviceRGBColor(CGContextRef context,float red,float green,float blue,float alpha);
|
||||
APPKIT_EXPORT void CGContextSetDeviceCMYKColor(CGContextRef context,float cyan,float magenta,float yellow,float black,float alpha);
|
||||
|
||||
APPKIT_EXPORT void CGContextSetCalibratedGrayColor(CGContextRef context,float gray,float alpha);
|
||||
APPKIT_EXPORT void CGContextSetCalibratedRGBColor(CGContextRef context,float red,float green,float blue,float alpha);
|
||||
|
||||
APPKIT_EXPORT void CGContextCopyBits(CGContextRef context,CGRect rect,CGPoint point,int gState);
|
||||
|
||||
APPKIT_EXPORT void CGContextSourceOverRGBAImage(CGContextRef context,CGRect rect,int width,int height,unsigned int *data,float fraction);
|
||||
|
||||
APPKIT_EXPORT void CGContextBitCopy(CGContextRef context,NSPoint dstOrigin,CGRenderingContext *deviceContext,NSPoint srcOrigin,NSSize size);
|
||||
|
||||
APPKIT_EXPORT void CGContextBeginDocument(CGContextRef context);
|
||||
APPKIT_EXPORT void CGContextScalePage(CGContextRef context,float scalex,float scaley);
|
||||
APPKIT_EXPORT void CGContextEndDocument(CGContextRef context);
|
244
AppKit/CoreGraphics.subproj/CGContext.m
Executable file
244
AppKit/CoreGraphics.subproj/CGContext.m
Executable file
@ -0,0 +1,244 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/CGContext.h>
|
||||
|
||||
@interface CGContext(CGContext_private)
|
||||
|
||||
-(void)saveGState;
|
||||
-(void)restoreGState;
|
||||
|
||||
-(CGAffineTransform)getCTM;
|
||||
-(void)concatCTM:(CGAffineTransform)transform;
|
||||
-(void)scaleCTM:(float)scalex:(float)scaley;
|
||||
-(void)translateCTM:(float)translatex:(float)translatey;
|
||||
-(void)rotateCTM:(float)radians;
|
||||
|
||||
-(CGAffineTransform)textMatrix;
|
||||
-(void)setTextMatrix:(CGAffineTransform)transform;
|
||||
|
||||
-(void)clipToRect:(NSRect)rect;
|
||||
-(void)clipToRects:(const NSRect *)rects count:(unsigned)count;
|
||||
|
||||
-(void)beginPath;
|
||||
-(void)closePath;
|
||||
-(void)moveToPoint:(float)x:(float)y;
|
||||
-(void)addLineToPoint:(float)x:(float)y;
|
||||
-(void)addArc:(float)x:(float)y:(float)radius:(float)startRadian:(float)endRadian:(int)clockwise;
|
||||
-(void)addArcToPoint:(float)x1:(float)y1:(float)x2:(float)y2:(float)radius;
|
||||
-(void)addCurveToPoint:(float)cx1:(float)cy1:(float)cx2:(float)cy2:(float)x:(float)y;
|
||||
|
||||
-(void)fillPath;
|
||||
-(void)fillRects:(const CGRect *)rects count:(unsigned)count;
|
||||
|
||||
-(void)setLineWidth:(float)width;
|
||||
|
||||
-(void)strokePath;
|
||||
-(void)strokeRect:(CGRect)rect width:(float)width;
|
||||
|
||||
-(void)selectFontWithName:(NSString *)name pointSize:(float)pointSize;
|
||||
-(void)moveto:(float)x:(float)y show:(const char *)cString:(int)length;
|
||||
-(void)showGlyphs:(const CGGlyph *)glyphs:(unsigned)numberOfGlyphs atPoint:(NSPoint)point;
|
||||
-(void)showGlyphs:(const CGGlyph *)glyphs advances:(const CGSize *)advances count:(unsigned)count;
|
||||
|
||||
-(void)beginPage:(const CGRect *)mediaBox;
|
||||
-(void)endPage;
|
||||
|
||||
-(void)setDeviceColorWhite:(float)white alpha:(float)alpha;
|
||||
-(void)setDeviceColorRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha;
|
||||
-(void)setDeviceColorCyan:(float)cyan magenta:(float)magenta yellow:(float)yellow black:(float)black alpha:(float)alpha;
|
||||
|
||||
-(void)setCalibratedColorWhite:(float)white alpha:(float)alpha;
|
||||
-(void)setCalibratedColorRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha;
|
||||
|
||||
-(void)copyBitsInRect:(NSRect)rect toPoint:(NSPoint)point gState:(int)gState;
|
||||
|
||||
-(void)drawRGBAImageInRect:(NSRect)rect width:(int)width height:(int)height data:(unsigned int *)data fraction:(float)fraction;
|
||||
|
||||
-(void)bitCopyToPoint:(NSPoint)dstOrigin renderingContext:(CGRenderingContext *)renderingContext fromPoint:(NSPoint)srcOrigin size:(NSSize)size;
|
||||
|
||||
-(void)beginDocument;
|
||||
-(void)scalePage:(float)scalex:(float)scaley;
|
||||
-(void)endDocument;
|
||||
|
||||
@end
|
||||
|
||||
@implementation CGContext
|
||||
|
||||
@end
|
||||
|
||||
void CGContextSaveGState(CGContext *context){
|
||||
[context saveGState];
|
||||
}
|
||||
|
||||
void CGContextRestoreGState(CGContext *context){
|
||||
[context restoreGState];
|
||||
}
|
||||
|
||||
CGAffineTransform CGContextGetCTM(CGContext *context) {
|
||||
return [context getCTM];
|
||||
}
|
||||
|
||||
void CGContextConcatCTM(CGContext *context,CGAffineTransform transform) {
|
||||
[context concatCTM:transform];
|
||||
}
|
||||
|
||||
void CGContextScaleCTM(CGContext *context,float scalex,float scaley){
|
||||
[context scaleCTM:scalex:scaley];
|
||||
}
|
||||
|
||||
void CGContextTranslateCTM(CGContext *context,float tx,float ty){
|
||||
[context translateCTM:tx:ty];
|
||||
}
|
||||
|
||||
void CGContextRotateCTM(CGContext *context,float radians) {
|
||||
[context rotateCTM:radians];
|
||||
}
|
||||
|
||||
CGAffineTransform CGContextGetTextMatrix(CGContextRef context) {
|
||||
return [context textMatrix];
|
||||
}
|
||||
|
||||
void CGContextSetTextMatrix(CGContextRef context, CGAffineTransform transform) {
|
||||
[context setTextMatrix:transform];
|
||||
}
|
||||
|
||||
void CGContextClipToRect(CGContext *context, CGRect rect){
|
||||
[context clipToRect:rect];
|
||||
}
|
||||
|
||||
void CGContextClipToRects(CGContext *context,const CGRect *rects,unsigned count) {
|
||||
[context clipToRects:rects count:count];
|
||||
}
|
||||
|
||||
void CGContextBeginPath(CGContextRef context) {
|
||||
[context beginPath];
|
||||
}
|
||||
|
||||
void CGContextClosePath(CGContextRef context) {
|
||||
[context closePath];
|
||||
}
|
||||
|
||||
void CGContextMoveToPoint(CGContextRef context,float x,float y) {
|
||||
[context moveToPoint:x:y];
|
||||
}
|
||||
|
||||
void CGContextAddLineToPoint(CGContextRef context,float x,float y) {
|
||||
[context addLineToPoint:x:y];
|
||||
}
|
||||
|
||||
void CGContextAddArc(CGContextRef context,float x,float y,float radius,float startRadian,float endRadian,int clockwise) {
|
||||
[context addArc:x:y:radius:startRadian:endRadian:clockwise];
|
||||
}
|
||||
|
||||
void CGContextAddArcToPoint(CGContextRef context,float x1,float y1,float x2,float y2,float radius) {
|
||||
[context addArcToPoint:x1:y1:x2:y2:radius];
|
||||
}
|
||||
|
||||
|
||||
void CGContextAddCurveToPoint(CGContextRef context,float cx1,float cy1,float cx2,float cy2,float x,float y) {
|
||||
[context addCurveToPoint:cx1:cy1:cx2:cy2:x:y];
|
||||
}
|
||||
|
||||
void CGContextFillPath(CGContextRef context) {
|
||||
[context fillPath];
|
||||
}
|
||||
|
||||
void CGContextFillRect(CGContext *context,CGRect rect) {
|
||||
[context fillRects:&rect count:1];
|
||||
}
|
||||
|
||||
void CGContextFillRects(CGContext *context,const CGRect *rects,unsigned count) {
|
||||
[context fillRects:rects count:count];
|
||||
}
|
||||
|
||||
void CGContextSetLineWidth(CGContextRef context,float width) {
|
||||
[context setLineWidth:width];
|
||||
}
|
||||
|
||||
void CGContextStrokePath(CGContextRef context) {
|
||||
[context strokePath];
|
||||
}
|
||||
|
||||
void CGContextStrokeRect(CGContext *context,CGRect rect) {
|
||||
[context strokeRect:rect width:1.0];
|
||||
}
|
||||
|
||||
void CGContextStrokeRectWithWidth(CGContext *context,CGRect rect,float width) {
|
||||
[context strokeRect:rect width:width];
|
||||
}
|
||||
|
||||
void CGContextSelectFont(CGContext *context,const char *name,float size,CGTextEncoding encoding) {
|
||||
[context selectFontWithName:[NSString stringWithCString:name] pointSize:size];
|
||||
}
|
||||
|
||||
void CGContextShowTextAtPoint(CGContext *context,float x,float y,const char *text,unsigned length) {
|
||||
[context moveto:x:y show:text:length];
|
||||
}
|
||||
|
||||
void CGContextShowGlyphsAtPoint(CGContext *context,float x,float y,const CGGlyph *glyphs,unsigned count) {
|
||||
[context showGlyphs:glyphs:count atPoint:NSMakePoint(x,y)];
|
||||
}
|
||||
|
||||
void CGContextShowGlyphsWithAdvances(CGContextRef context,const CGGlyph *glyphs,const CGSize *advances,unsigned count) {
|
||||
[context showGlyphs:glyphs advances:advances count:count];
|
||||
}
|
||||
|
||||
void CGContextBeginPage(CGContext *context,const CGRect *mediaBox) {
|
||||
[context beginPage:mediaBox];
|
||||
}
|
||||
|
||||
void CGContextEndPage(CGContext *context) {
|
||||
[context endPage];
|
||||
}
|
||||
|
||||
void CGContextSetDeviceGrayColor(CGContext *context,float gray,float alpha) {
|
||||
[context setDeviceColorWhite:gray alpha:alpha];
|
||||
}
|
||||
|
||||
void CGContextSetDeviceRGBColor(CGContext *context,float red,float green,float blue,float alpha) {
|
||||
[context setDeviceColorRed:red green:green blue:blue alpha:alpha];
|
||||
}
|
||||
|
||||
void CGContextSetDeviceCMYKColor(CGContext *context,float cyan,float magenta,float yellow,float black,float alpha) {
|
||||
[context setDeviceColorCyan:cyan magenta:magenta yellow:yellow black:black alpha:alpha];
|
||||
}
|
||||
|
||||
void CGContextSetCalibratedGrayColor(CGContext *context,float gray,float alpha) {
|
||||
[context setCalibratedColorWhite:gray alpha:alpha];
|
||||
}
|
||||
|
||||
void CGContextSetCalibratedRGBColor(CGContext *context,float red,float green,float blue,float alpha) {
|
||||
[context setCalibratedColorRed:red green:green blue:blue alpha:alpha];
|
||||
}
|
||||
|
||||
void CGContextCopyBits(CGContext *context,CGRect rect,CGPoint point,int gState) {
|
||||
[context copyBitsInRect:rect toPoint:point gState:gState];
|
||||
}
|
||||
|
||||
void CGContextSourceOverRGBAImage(CGContext *context,CGRect rect,int width,int height,unsigned int *data,float fraction) {
|
||||
[context drawRGBAImageInRect:rect width:width height:height data:data fraction:fraction];
|
||||
}
|
||||
|
||||
void CGContextBitCopy(CGContext *context,NSPoint dstOrigin,CGRenderingContext *renderingContext,NSPoint srcOrigin,NSSize size) {
|
||||
[context bitCopyToPoint:dstOrigin renderingContext:renderingContext fromPoint:srcOrigin size:size];
|
||||
}
|
||||
|
||||
void CGContextBeginDocument(CGContext *context) {
|
||||
[context beginDocument];
|
||||
}
|
||||
|
||||
void CGContextScalePage(CGContext *context,float scalex,float scaley) {
|
||||
[context scalePage:scalex:scaley];
|
||||
}
|
||||
|
||||
void CGContextEndDocument(CGContext *context) {
|
||||
[context endDocument];
|
||||
}
|
||||
|
23
AppKit/CoreGraphics.subproj/CGContextSimple.h
Executable file
23
AppKit/CoreGraphics.subproj/CGContextSimple.h
Executable file
@ -0,0 +1,23 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/CGContext.h>
|
||||
|
||||
@class CGRenderingContext;
|
||||
|
||||
@interface CGContextSimple : CGContext {
|
||||
CGRenderingContext *_renderingContext;
|
||||
CGAffineTransform _deviceTransform;
|
||||
NSRect _clipRect;
|
||||
|
||||
NSMutableArray *_stateStack;
|
||||
}
|
||||
|
||||
-initWithRenderingContext:(CGRenderingContext *)renderingContext transform:(CGAffineTransform)deviceTransform clipRect:(NSRect)clipRect;
|
||||
|
||||
@end
|
226
AppKit/CoreGraphics.subproj/CGContextSimple.m
Executable file
226
AppKit/CoreGraphics.subproj/CGContextSimple.m
Executable file
@ -0,0 +1,226 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/CGContextSimple.h>
|
||||
#import <AppKit/CGGraphicsState.h>
|
||||
#import <AppKit/CGRenderingContext.h>
|
||||
|
||||
@implementation CGContextSimple
|
||||
|
||||
-initWithRenderingContext:(CGRenderingContext *)renderingContext transform:(CGAffineTransform)deviceTransform clipRect:(NSRect)clipRect {
|
||||
_renderingContext=[renderingContext retain];
|
||||
_deviceTransform=deviceTransform;
|
||||
_clipRect=clipRect;
|
||||
_stateStack=[NSMutableArray new];
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)dealloc {
|
||||
[_renderingContext release];
|
||||
[_stateStack release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
static inline CGGraphicsState *currentState(CGContextSimple *self){
|
||||
return [self->_stateStack lastObject];
|
||||
}
|
||||
|
||||
-(CGGraphicsState *)currentState {
|
||||
return currentState(self);
|
||||
}
|
||||
|
||||
-(void)saveGState {
|
||||
CGGraphicsState *current=currentState(self),*next;
|
||||
|
||||
[current save];
|
||||
next=[current copy];
|
||||
[_stateStack addObject:next];
|
||||
[next release];
|
||||
}
|
||||
|
||||
-(void)restoreGState {
|
||||
[[_stateStack lastObject] abort];
|
||||
[_stateStack removeLastObject];
|
||||
[currentState(self) restore];
|
||||
}
|
||||
|
||||
-(void)scaleCTM:(float)scalex:(float)scaley {
|
||||
[currentState(self) scaleCTM:scalex:scaley];
|
||||
}
|
||||
|
||||
-(void)translateCTM:(float)tx:(float)ty {
|
||||
[currentState(self) translateCTM:tx:ty];
|
||||
}
|
||||
|
||||
-(void)concatCTM:(CGAffineTransform)transform {
|
||||
[currentState(self) concatCTM:transform];
|
||||
}
|
||||
|
||||
-(void)setLineWidth:(float)width {
|
||||
[currentState(self) setLineWidth:width];
|
||||
}
|
||||
|
||||
-(void)beginPath {
|
||||
[currentState(self) beginPath];
|
||||
}
|
||||
|
||||
-(void)moveToPoint:(float)x:(float)y {
|
||||
[currentState(self) moveToPoint:x:y];
|
||||
}
|
||||
|
||||
-(void)addLineToPoint:(float)x:(float)y {
|
||||
[currentState(self) addLineToPoint:x:y];
|
||||
}
|
||||
|
||||
-(void)addCurveToPoint:(float)cx1:(float)cy1:(float)cx2:(float)cy2:(float)x:(float)y {
|
||||
[currentState(self) addCurveToPoint:cx1:cy1:cx2:cy2:x:y];
|
||||
}
|
||||
|
||||
-(void)closePath {
|
||||
[currentState(self) closePath];
|
||||
}
|
||||
|
||||
-(void)addArc:(float)x:(float)y:(float)radius:(float)startRadian:(float)endRadian:(int)clockwise {
|
||||
[currentState(self) addArc:x:y:radius:startRadian:endRadian:clockwise];
|
||||
}
|
||||
|
||||
-(void)addArcToPoint:(float)x1:(float)y1:(float)x2:(float)y2:(float)radius {
|
||||
[currentState(self) addArcToPoint:x1:y1:x2:y2:radius];
|
||||
}
|
||||
|
||||
-(void)fillPath {
|
||||
[currentState(self) fillPath];
|
||||
}
|
||||
|
||||
-(void)strokePath {
|
||||
[currentState(self) strokePath];
|
||||
}
|
||||
|
||||
-(void)setDeviceColorRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha {
|
||||
[currentState(self) setDeviceColorRed:red green:green blue:blue alpha:alpha];
|
||||
}
|
||||
|
||||
-(void)setDeviceColorWhite:(float)white alpha:(float)alpha {
|
||||
[self setDeviceColorRed:white green:white blue:white alpha:alpha];
|
||||
}
|
||||
|
||||
-(void)setDeviceColorCyan:(float)cyan magenta:(float)magenta yellow:(float)yellow black:(float)black alpha:(float)alpha {
|
||||
NSUnimplementedMethod();
|
||||
}
|
||||
|
||||
-(void)setCalibratedColorRed:(float)r green:(float)g blue:(float)b alpha:(float)alpha {
|
||||
// NeXT gamma is 2.2 I think, my PC card is probably 1.3. This should be
|
||||
// assumed = PC card setting
|
||||
// display = NeXT 2.2
|
||||
// I think.
|
||||
|
||||
const float assumedGamma=1.3;
|
||||
const float displayGamma=2.2;
|
||||
|
||||
r=pow(r,assumedGamma/displayGamma);
|
||||
if(r>1.0)
|
||||
r=1.0;
|
||||
|
||||
g=pow(g,assumedGamma/displayGamma);
|
||||
if(g>1.0)
|
||||
g=1.0;
|
||||
|
||||
b=pow(b,assumedGamma/displayGamma);
|
||||
if(b>1.0)
|
||||
b=1.0;
|
||||
|
||||
[self setDeviceColorRed:r green:g blue:b alpha:alpha];
|
||||
}
|
||||
|
||||
-(void)setCalibratedColorWhite:(float)white alpha:(float)alpha {
|
||||
[self setCalibratedColorRed:white green:white blue:white alpha:alpha];
|
||||
}
|
||||
|
||||
-(void)selectFontWithName:(NSString *)name pointSize:(float)pointSize {
|
||||
[currentState(self) selectFontWithName:name pointSize:pointSize];
|
||||
}
|
||||
|
||||
-(void)setTextMatrix:(CGAffineTransform)transform {
|
||||
[currentState(self) setTextMatrix:transform];
|
||||
}
|
||||
|
||||
-(CGAffineTransform)textMatrix {
|
||||
return [currentState(self) textMatrix];
|
||||
}
|
||||
|
||||
-(void)moveto:(float)x:(float)y
|
||||
show:(const char *)cString:(int)length {
|
||||
[currentState(self) moveto:x:y ashow:cString:length:0:0];
|
||||
}
|
||||
|
||||
-(void)moveto:(float)x:(float)y
|
||||
ashow:(const char *)cString:(int)length:(float)dx:(float)dy {
|
||||
[currentState(self) moveto:x:y ashow:cString:length:dx:dy];
|
||||
}
|
||||
|
||||
-(void)showGlyphs:(const CGGlyph *)glyphs:(unsigned)numberOfGlyphs atPoint:(NSPoint)point {
|
||||
[currentState(self) showGlyphs:glyphs:numberOfGlyphs atPoint:point];
|
||||
}
|
||||
|
||||
-(void)showGlyphs:(const CGGlyph *)glyphs advances:(const CGSize *)advances count:(unsigned)count {
|
||||
[currentState(self) showGlyphs:glyphs advances:advances count:count];
|
||||
}
|
||||
|
||||
|
||||
-(void)drawRGBAImageInRect:(NSRect)rect width:(int)width height:(int)height data:(unsigned int *)data fraction:(float)fraction {
|
||||
[currentState(self) drawRGBAImageInRect:rect width:width height:height data:data fraction:fraction];
|
||||
}
|
||||
|
||||
-(void)copyBitsInRect:(NSRect)rect toPoint:(NSPoint)point gState:(int)gState {
|
||||
[currentState(self) copyBitsInRect:rect toPoint:point];
|
||||
}
|
||||
|
||||
-(void)fillRects:(const CGRect *)rects count:(unsigned)count {
|
||||
[currentState(self) fillRects:rects count:count];
|
||||
}
|
||||
|
||||
-(void)strokeRect:(CGRect)strokeRect width:(float)width {
|
||||
[currentState(self) strokeRect:strokeRect width:width];
|
||||
}
|
||||
|
||||
-(void)clipToRect:(NSRect)rect {
|
||||
[currentState(self) clipToRect:rect];
|
||||
}
|
||||
|
||||
-(void)clipToRects:(const NSRect *)rects count:(unsigned)count {
|
||||
[currentState(self) clipToRects:rects count:count];
|
||||
}
|
||||
|
||||
-(void)bitCopyToPoint:(NSPoint)dstOrigin renderingContext:(CGRenderingContext *)renderingContext fromPoint:(NSPoint)srcOrigin size:(NSSize)size {
|
||||
[currentState(self) bitCopyToPoint:dstOrigin renderingContext:renderingContext fromPoint:srcOrigin size:size];
|
||||
}
|
||||
|
||||
// printing
|
||||
|
||||
-(void)beginPage:(const CGRect *)mediaBox {
|
||||
[_renderingContext beginPage];
|
||||
}
|
||||
|
||||
-(void)endPage {
|
||||
[_renderingContext endPage];
|
||||
}
|
||||
|
||||
-(void)beginDocument {
|
||||
[_renderingContext beginDocument];
|
||||
}
|
||||
|
||||
-(void)scalePage:(float)scalex:(float)scaley {
|
||||
[_renderingContext scalePage:scalex:scaley];
|
||||
}
|
||||
|
||||
-(void)endDocument {
|
||||
[_renderingContext endDocument];
|
||||
}
|
||||
|
||||
@end
|
13
AppKit/CoreGraphics.subproj/CGEvent.h
Executable file
13
AppKit/CoreGraphics.subproj/CGEvent.h
Executable file
@ -0,0 +1,13 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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 <Foundation/Foundation.h>
|
||||
|
||||
@interface CGEvent : NSObject
|
||||
|
||||
@end
|
14
AppKit/CoreGraphics.subproj/CGEvent.m
Executable file
14
AppKit/CoreGraphics.subproj/CGEvent.m
Executable file
@ -0,0 +1,14 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/CGEvent.h>
|
||||
|
||||
@implementation CGEvent
|
||||
|
||||
@end
|
11
AppKit/CoreGraphics.subproj/CGFont.h
Executable file
11
AppKit/CoreGraphics.subproj/CGFont.h
Executable file
@ -0,0 +1,11 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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 <Foundation/Foundation.h>
|
||||
|
||||
typedef unsigned short CGGlyph;
|
11
AppKit/CoreGraphics.subproj/CGFont.m
Executable file
11
AppKit/CoreGraphics.subproj/CGFont.m
Executable file
@ -0,0 +1,11 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/CGFont.h>
|
||||
|
18
AppKit/CoreGraphics.subproj/CGGeometry.h
Executable file
18
AppKit/CoreGraphics.subproj/CGGeometry.h
Executable file
@ -0,0 +1,18 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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 <Foundation/Foundation.h>
|
||||
|
||||
typedef NSPoint CGPoint;
|
||||
typedef NSSize CGSize;
|
||||
typedef NSRect CGRect;
|
||||
|
||||
static inline CGRect CGRectMake(float x, float y, float width, float height) {
|
||||
return NSMakeRect(x,y,width,height);
|
||||
}
|
||||
|
11
AppKit/CoreGraphics.subproj/CGGeometry.m
Executable file
11
AppKit/CoreGraphics.subproj/CGGeometry.m
Executable file
@ -0,0 +1,11 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/CGGeometry.h>
|
||||
|
76
AppKit/CoreGraphics.subproj/CGGraphicsState.h
Executable file
76
AppKit/CoreGraphics.subproj/CGGraphicsState.h
Executable file
@ -0,0 +1,76 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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 <Foundation/NSObject.h>
|
||||
#import <Foundation/NSGeometry.h>
|
||||
#import <AppKit/CGAffineTransform.h>
|
||||
#import <AppKit/CGFont.h>
|
||||
#import <AppKit/CGGeometry.h>
|
||||
|
||||
@class CGRenderingContext;
|
||||
|
||||
@interface CGGraphicsState : NSObject <NSCopying> {
|
||||
CGRenderingContext *_renderingContext;
|
||||
CGAffineTransform _deviceTransform;
|
||||
NSRect _clipRect;
|
||||
}
|
||||
|
||||
-initWithRenderingContext:(CGRenderingContext *)context transform:(CGAffineTransform)deviceTransform clipRect:(NSRect)clipRect;
|
||||
|
||||
// primitives
|
||||
-(void)moveToPoint:(float)x:(float)y;
|
||||
-(void)addLineToPoint:(float)x:(float)y;
|
||||
// --
|
||||
|
||||
-(void)addCurveToPoint:(float)cx1:(float)cy1:(float)cx2:(float)cy2:(float)x:(float)y;
|
||||
|
||||
-(void)addArc:(float)x:(float)y:(float)radius:(float)startRadian:(float)endRadian:(int)clockwise;
|
||||
|
||||
|
||||
-(void)save;
|
||||
-(void)restore;
|
||||
-(void)abort;
|
||||
|
||||
-(void)clipToRect:(NSRect)clipRect;
|
||||
-(void)clipToRects:(const NSRect *)rects count:(unsigned)count;
|
||||
|
||||
-(void)scaleCTM:(float)scalex:(float)scaley;
|
||||
-(void)translateCTM:(float)tx:(float)ty;
|
||||
-(void)concatCTM:(CGAffineTransform)transform;
|
||||
|
||||
-(void)beginPath;
|
||||
-(void)closePath;
|
||||
-(void)addArcToPoint:(float)x1:(float)y1:(float)x2:(float)y2:(float)radius;
|
||||
-(void)fillPath;
|
||||
-(void)strokePath;
|
||||
|
||||
-(void)setDeviceColorRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha;
|
||||
|
||||
-(void)selectFontWithName:(NSString *)name pointSize:(float)pointSize;
|
||||
-(void)setTextMatrix:(CGAffineTransform)transform;
|
||||
-(CGAffineTransform)textMatrix;
|
||||
-(void)moveto:(float)x:(float)y
|
||||
ashow:(const char *)cString:(int)length:(float)dx:(float)dy;
|
||||
|
||||
-(void)showGlyphs:(const CGGlyph *)glyphs:(unsigned)numberOfGlyphs atPoint:(NSPoint)point;
|
||||
-(void)showGlyphs:(const CGGlyph *)glyphs advances:(const CGSize *)advances count:(unsigned)count;
|
||||
|
||||
-(void)copyBitsInRect:(NSRect)rect toPoint:(NSPoint)point;
|
||||
-(void)fillRects:(const CGRect *)rects count:(unsigned)count;
|
||||
-(void)strokeRect:(CGRect)strokeRect width:(float)width;
|
||||
|
||||
-(float)lineWidth;
|
||||
-(void)setLineWidth:(float)width;
|
||||
|
||||
-(void)drawRGBAImageInRect:(NSRect)rect width:(int)width height:(int)height data:(unsigned int *)data fraction:(float)fraction;
|
||||
|
||||
-(void)bitCopyToPoint:(NSPoint)dstOrigin renderingContext:(CGRenderingContext *)renderingContext fromPoint:(NSPoint)srcOrigin size:(NSSize)size;
|
||||
|
||||
@end
|
||||
|
||||
void CGGraphicsSourceOver_rgba32_onto_bgrx32(unsigned char *sourceRGBA,unsigned char *resultRGBX,int width,int height,float fraction);
|
268
AppKit/CoreGraphics.subproj/CGGraphicsState.m
Executable file
268
AppKit/CoreGraphics.subproj/CGGraphicsState.m
Executable file
@ -0,0 +1,268 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/CGGraphicsState.h>
|
||||
#import <AppKit/CGRenderingContext.h>
|
||||
|
||||
#import <AppKit/CoreGraphics.h>
|
||||
|
||||
// Bezier and arc to bezier algorithms from: Windows Graphics Programming by Feng Yuan
|
||||
|
||||
@implementation CGGraphicsState
|
||||
|
||||
-initWithRenderingContext:(CGRenderingContext *)context transform:(CGAffineTransform)deviceTransform clipRect:(NSRect)clipRect {
|
||||
_renderingContext=[context retain];
|
||||
_deviceTransform=deviceTransform;
|
||||
_clipRect=clipRect;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)dealloc {
|
||||
[_renderingContext release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
-copyWithZone:(NSZone *)zone {
|
||||
CGGraphicsState *copy=NSCopyObject(self,0,zone);
|
||||
|
||||
copy->_renderingContext=[_renderingContext retain];
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
-(void)moveToPoint:(float)x:(float)y {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-(void)addLineToPoint:(float)x:(float)y {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
static void bezier(CGGraphicsState *self,double x1,double y1,double x2, double y2,double x3,double y3,double x4,double y4){
|
||||
// Ax+By+C=0 is the line (x1,y1) (x4,y4);
|
||||
double A=y4-y1;
|
||||
double B=x1-x4;
|
||||
double C=y1*(x4-x1)-x1*(y4-y1);
|
||||
double AB=A*A+B*B;
|
||||
|
||||
if((A*x2+B*y2+C)*(A*x2+B*y2+C)<AB &&
|
||||
(A*x3+B*y3+C)*(A*x3+B*y3+C)<AB){
|
||||
[self moveToPoint:x1:y1];
|
||||
[self addLineToPoint:x4:y4];
|
||||
return;
|
||||
}
|
||||
else {
|
||||
double x12=x1+x2;
|
||||
double y12=y1+y2;
|
||||
double x23=x2+x3;
|
||||
double y23=y2+y3;
|
||||
double x34=x3+x4;
|
||||
double y34=y3+y4;
|
||||
double x1223=x12+x23;
|
||||
double y1223=y12+y23;
|
||||
double x2334=x23+x34;
|
||||
double y2334=y23+y34;
|
||||
double x=x1223+x2334;
|
||||
double y=y1223+y2334;
|
||||
|
||||
bezier(self,x1,y1,x12/2,y12/2,x1223/4,y1223/4,x/8,y/8);
|
||||
bezier(self,x/8,y/8,x2334/4,y2334/4,x34/2,y34/2,x4,y4);
|
||||
}
|
||||
}
|
||||
|
||||
-(void)addCurveToPoint:(float)cx1:(float)cy1:(float)cx2:(float)cy2:(float)x:(float)y {
|
||||
// bezier(self,_currentPoint.x,_currentPoint.y,cx1,cy1,cx2,cy2,x,y);
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-(void)addArc:(float)x:(float)y:(float)radius:(float)startRadian:(float)endRadian:(int)clockwise {
|
||||
// This is not complete, doesn't handle clockwise and probably doesn't manipulate the current
|
||||
// point properly
|
||||
float radiusx=radius,radiusy=radius;
|
||||
double remainder=endRadian-startRadian;
|
||||
double delta=3.141592653589793238/2; // 90 degrees
|
||||
int i;
|
||||
|
||||
for(;remainder>0;startRadian+=delta,remainder-=delta){
|
||||
double sweepangle=(remainder>delta)?delta:remainder;
|
||||
double XY[8];
|
||||
NSPoint points[4];
|
||||
double B=sin(sweepangle/2);
|
||||
double C=cos(sweepangle/2);
|
||||
double A=1-C;
|
||||
double X=A*4/3;
|
||||
double Y=B-X*(1-A)/B;
|
||||
double s=sin(startRadian+sweepangle/2);
|
||||
double c=cos(startRadian+sweepangle/2);
|
||||
|
||||
XY[0]= C;
|
||||
XY[1]=-B;
|
||||
XY[2]= C+X;
|
||||
XY[3]=-Y;
|
||||
XY[4]= C+X;
|
||||
XY[5]= Y;
|
||||
XY[6]= C;
|
||||
XY[7]= B;
|
||||
|
||||
for(i=0;i<4;i++){
|
||||
points[i].x=x+(XY[i*2]*c-XY[i*2+1]*s)*radiusx;
|
||||
points[i].y=y+(XY[i*2]*s+XY[i*2+1]*c)*radiusy;
|
||||
}
|
||||
|
||||
[self moveToPoint:points[0].x:points[0].y];
|
||||
[self addCurveToPoint:points[1].x:points[1].y:points[2].x:points[2].y:points[3].x:points[3].y];
|
||||
}
|
||||
}
|
||||
|
||||
-(void)save {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-(void)restore {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-(void)abort {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-(void)clipToRect:(NSRect)clipRect {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-(void)clipToRects:(const NSRect *)rects count:(unsigned)count {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
|
||||
-(void)scaleCTM:(float)scalex:(float)scaley {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-(void)translateCTM:(float)tx:(float)ty {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-(void)concatCTM:(CGAffineTransform)transform {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
|
||||
-(void)beginPath {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-(void)closePath {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-(void)addArcToPoint:(float)x1:(float)y1:(float)x2:(float)y2:(float)radius {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-(void)fillPath {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-(void)strokePath {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-(void)setDeviceColorRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-(void)selectFontWithName:(NSString *)name pointSize:(float)pointSize {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-(void)setTextMatrix:(CGAffineTransform)transform {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-(CGAffineTransform)textMatrix {
|
||||
NSInvalidAbstractInvocation();
|
||||
return CGAffineTransformIdentity;
|
||||
}
|
||||
|
||||
-(void)moveto:(float)x:(float)y
|
||||
ashow:(const char *)cString:(int)length:(float)dx:(float)dy {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
|
||||
-(void)showGlyphs:(const CGGlyph *)glyphs:(unsigned)numberOfGlyphs atPoint:(NSPoint)point {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-(void)showGlyphs:(const CGGlyph *)glyphs advances:(const CGSize *)advances count:(unsigned)count {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-(void)copyBitsInRect:(NSRect)rect toPoint:(NSPoint)point {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-(void)fillRects:(const CGRect *)rects count:(unsigned)count {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-(void)strokeRect:(CGRect)strokeRect width:(float)width {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-(float)lineWidth {
|
||||
NSInvalidAbstractInvocation();
|
||||
return 0;
|
||||
}
|
||||
|
||||
-(void)setLineWidth:(float)width {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-(void)drawRGBAImageInRect:(NSRect)rect width:(int)width height:(int)height data:(unsigned int *)data fraction:(float)fraction {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-(void)bitCopyToPoint:(NSPoint)dstOrigin renderingContext:(CGRenderingContext *)renderingContext fromPoint:(NSPoint)srcOrigin size:(NSSize)size {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
void CGGraphicsSourceOver_rgba32_onto_bgrx32(unsigned char *sourceRGBA,unsigned char *resultBGRX,int width,int height,float fraction) {
|
||||
int sourceIndex=0;
|
||||
int sourceLength=width*height*4;
|
||||
int destinationReadIndex=0;
|
||||
int destinationWriteIndex=0;
|
||||
|
||||
while(sourceIndex<sourceLength){
|
||||
unsigned srcr=sourceRGBA[sourceIndex++];
|
||||
unsigned srcg=sourceRGBA[sourceIndex++];
|
||||
unsigned srcb=sourceRGBA[sourceIndex++];
|
||||
unsigned srca=sourceRGBA[sourceIndex++]*fraction;
|
||||
|
||||
unsigned dstb=resultBGRX[destinationReadIndex++];
|
||||
unsigned dstg=resultBGRX[destinationReadIndex++];
|
||||
unsigned dstr=resultBGRX[destinationReadIndex++];
|
||||
unsigned dsta=255-srca;
|
||||
|
||||
destinationReadIndex++;
|
||||
|
||||
dstr=(srcr*srca+dstr*dsta)>>8;
|
||||
dstg=(srcg*srca+dstg*dsta)>>8;
|
||||
dstb=(srcb*srca+dstb*dsta)>>8;
|
||||
|
||||
resultBGRX[destinationWriteIndex++]=dstb;
|
||||
resultBGRX[destinationWriteIndex++]=dstg;
|
||||
resultBGRX[destinationWriteIndex++]=dstr;
|
||||
destinationWriteIndex++; // skip x
|
||||
}
|
||||
}
|
27
AppKit/CoreGraphics.subproj/CGImage.h
Executable file
27
AppKit/CoreGraphics.subproj/CGImage.h
Executable file
@ -0,0 +1,27 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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 <Foundation/NSObject.h>
|
||||
|
||||
@interface CGImage : NSObject {
|
||||
#if 0
|
||||
unsigned _width;
|
||||
unsigned _height;
|
||||
unsigned _bitsPerComponent;
|
||||
unsigned _bitsPerPixel;
|
||||
unsigned _bytesPerRow;
|
||||
CGColorSpaceRef _colorSpace;
|
||||
CGImageAlphaInfo _alphaInfo;
|
||||
CGDataProviderRef _dataProvider;
|
||||
#endif
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
typedef CGImage *CGImageRef;
|
||||
|
13
AppKit/CoreGraphics.subproj/CGImage.m
Executable file
13
AppKit/CoreGraphics.subproj/CGImage.m
Executable file
@ -0,0 +1,13 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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 "CGImage.h"
|
||||
|
||||
@implementation CGImage
|
||||
|
||||
@end
|
27
AppKit/CoreGraphics.subproj/CGRenderingContext.h
Executable file
27
AppKit/CoreGraphics.subproj/CGRenderingContext.h
Executable file
@ -0,0 +1,27 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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 <Foundation/Foundation.h>
|
||||
#import <AppKit/CGAffineTransform.h>
|
||||
|
||||
@class CGContext;
|
||||
|
||||
@interface CGRenderingContext : NSObject
|
||||
|
||||
-(NSSize)size;
|
||||
|
||||
-(CGContext *)graphicsContextWithTransform:(CGAffineTransform)transform clipRect:(NSRect)clipRect;
|
||||
|
||||
-(void)beginPage;
|
||||
-(void)endPage;
|
||||
-(void)beginDocument;
|
||||
-(void)endDocument;
|
||||
|
||||
-(void)scalePage:(float)scalex:(float)scaley;
|
||||
|
||||
@end
|
43
AppKit/CoreGraphics.subproj/CGRenderingContext.m
Executable file
43
AppKit/CoreGraphics.subproj/CGRenderingContext.m
Executable file
@ -0,0 +1,43 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/CGRenderingContext.h>
|
||||
|
||||
@implementation CGRenderingContext
|
||||
|
||||
-(NSSize)size {
|
||||
return NSZeroSize;
|
||||
}
|
||||
|
||||
-(CGContext *)graphicsContextWithTransform:(CGAffineTransform)transform clipRect:(NSRect)clipRect {
|
||||
NSInvalidAbstractInvocation();
|
||||
return nil;
|
||||
}
|
||||
|
||||
-(void)beginPage {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-(void)endPage {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-(void)beginDocument {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-(void)endDocument {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-(void)scalePage:(float)scalex:(float)scaley {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
@end
|
70
AppKit/CoreGraphics.subproj/CGWindow.h
Executable file
70
AppKit/CoreGraphics.subproj/CGWindow.h
Executable file
@ -0,0 +1,70 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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 <Foundation/Foundation.h>
|
||||
|
||||
@class CGRenderingContext,CGEvent;
|
||||
|
||||
@interface CGWindow : NSObject
|
||||
|
||||
-(void)setDelegate:delegate;
|
||||
-delegate;
|
||||
|
||||
-(void)invalidate;
|
||||
|
||||
-(CGRenderingContext *)renderingContext;
|
||||
|
||||
-(void)setTitle:(NSString *)title;
|
||||
-(void)setFrame:(NSRect)frame;
|
||||
|
||||
-(void)showWindowForAppActivation:(NSRect)frame;
|
||||
-(void)hideWindowForAppDeactivation:(NSRect)frame;
|
||||
|
||||
-(void)hideWindow;
|
||||
|
||||
-(void)placeAboveWindow:(CGWindow *)other;
|
||||
-(void)placeBelowWindow:(CGWindow *)other;
|
||||
|
||||
-(void)makeKey;
|
||||
-(void)captureEvents;
|
||||
-(void)miniaturize;
|
||||
-(void)deminiaturize;
|
||||
|
||||
-(void)flushBuffer;
|
||||
|
||||
-(NSPoint)mouseLocationOutsideOfEventStream;
|
||||
|
||||
-(void)sendEvent:(CGEvent *)event;
|
||||
|
||||
@end
|
||||
|
||||
@interface NSObject(CGWindow_delegate)
|
||||
|
||||
-(void)platformWindow:(CGWindow *)window frameChanged:(NSRect)frame;
|
||||
-(NSSize)platformWindow:(CGWindow *)window frameSizeWillChange:(NSSize)size;
|
||||
-(void)platformWindowWillBeginSizing:(CGWindow *)window;
|
||||
-(void)platformWindowDidEndSizing:(CGWindow *)window;
|
||||
-(void)platformWindowExitMove:(CGWindow *)window;
|
||||
|
||||
-(void)platformWindow:(CGWindow *)window needsDisplayInRect:(NSRect)rect;
|
||||
-(void)platformWindowStyleChanged:(CGWindow *)window;
|
||||
-(void)platformWindowWillClose:(CGWindow *)window;
|
||||
|
||||
-(void)platformWindowWillMove:(CGWindow *)window;
|
||||
-(void)platformWindowDidMove:(CGWindow *)window;
|
||||
|
||||
-(void)platformWindowDeminiaturized:(CGWindow *)window;
|
||||
-(void)platformWindowMiniaturized:(CGWindow *)window;
|
||||
-(void)platformWindowActivated:(CGWindow *)window;
|
||||
-(void)platformWindowDeactivated:(CGWindow *)window checkForAppDeactivation:(BOOL)checkForApp;
|
||||
|
||||
-(BOOL)platformWindowIgnoreModalMessages:(CGWindow *)window;
|
||||
|
||||
-(BOOL)platformWindowSetCursorEvent:(CGWindow *)window;
|
||||
|
||||
@end
|
99
AppKit/CoreGraphics.subproj/CGWindow.m
Executable file
99
AppKit/CoreGraphics.subproj/CGWindow.m
Executable file
@ -0,0 +1,99 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/CGWindow.h>
|
||||
|
||||
@implementation CGWindow
|
||||
|
||||
-(void)setDelegate:delegate {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-delegate {
|
||||
NSInvalidAbstractInvocation();
|
||||
return nil;
|
||||
}
|
||||
|
||||
-(void)invalidate {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
|
||||
-(CGRenderingContext *)renderingContext {
|
||||
NSInvalidAbstractInvocation();
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
||||
-(void)setTitle:(NSString *)title {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-(void)setFrame:(NSRect)frame {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
|
||||
-(void)showWindowForAppActivation:(NSRect)frame {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-(void)hideWindowForAppDeactivation:(NSRect)frame {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
|
||||
-(void)hideWindow {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
|
||||
-(void)placeAboveWindow:(CGWindow *)other {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-(void)placeBelowWindow:(CGWindow *)other {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
|
||||
-(void)makeKey {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-(void)captureEvents {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-(void)miniaturize {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-(void)deminiaturize {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
|
||||
-(void)flushBuffer {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
|
||||
-(NSPoint)mouseLocationOutsideOfEventStream {
|
||||
NSInvalidAbstractInvocation();
|
||||
return NSZeroPoint;
|
||||
}
|
||||
|
||||
|
||||
-(void)sendEvent:(CGEvent *)event {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
|
||||
@end
|
13
AppKit/CoreGraphics.subproj/CoreGraphics.h
Executable file
13
AppKit/CoreGraphics.subproj/CoreGraphics.h
Executable file
@ -0,0 +1,13 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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 <Foundation/Foundation.h>
|
||||
|
||||
#import <AppKit/CGContext.h>
|
||||
#import <AppKit/CGGeometry.h>
|
||||
#import <AppKit/CGAffineTransform.h>
|
21
AppKit/English.lproj/NSMenu.plist
Executable file
21
AppKit/English.lproj/NSMenu.plist
Executable file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"\UF700"="Up arrow";
|
||||
"\UF701"="Down arrow";
|
||||
"\UF702"="Left arrow";
|
||||
"\UF703"="Right arrow";
|
||||
|
||||
"\UF704"="F1";
|
||||
"\UF705"="F2";
|
||||
"\UF706"="F3";
|
||||
"\UF707"="F4";
|
||||
"\UF708"="F5";
|
||||
"\UF709"="F6";
|
||||
"\UF70A"="F7";
|
||||
"\UF70B"="F8";
|
||||
"\UF70C"="F9";
|
||||
"\UF70D"="F10";
|
||||
"\UF70E"="F11";
|
||||
"\UF70F"="F12";
|
||||
|
||||
/* ... */
|
||||
}
|
26
AppKit/English.lproj/NSToolbarCustomizationPalette.nib/classes.nib
generated
Normal file
26
AppKit/English.lproj/NSToolbarCustomizationPalette.nib/classes.nib
generated
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
IBClasses = (
|
||||
{CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; },
|
||||
{
|
||||
ACTIONS = {customizationPaletteDidFinish = id; settingsChanged = id; };
|
||||
CLASS = NSToolbarCustomizationPalette;
|
||||
LANGUAGE = ObjC;
|
||||
OUTLETS = {
|
||||
"_allowedItemsTextField" = id;
|
||||
"_button" = id;
|
||||
"_defaultItemsTextField" = id;
|
||||
"_displayModePopUp" = id;
|
||||
"_palette" = id;
|
||||
"_smallSizeModeButton" = id;
|
||||
};
|
||||
SUPERCLASS = NSPanel;
|
||||
},
|
||||
{
|
||||
CLASS = "_NSPaletteOwner";
|
||||
LANGUAGE = ObjC;
|
||||
OUTLETS = {palette = id; };
|
||||
SUPERCLASS = NSObject;
|
||||
}
|
||||
);
|
||||
IBVersion = 1;
|
||||
}
|
18
AppKit/English.lproj/NSToolbarCustomizationPalette.nib/info.nib
generated
Normal file
18
AppKit/English.lproj/NSToolbarCustomizationPalette.nib/info.nib
generated
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>IBDocumentLocation</key>
|
||||
<string>279 258 356 240 0 0 1600 1178 </string>
|
||||
<key>IBFramework Version</key>
|
||||
<string>446.1</string>
|
||||
<key>IBOpenObjects</key>
|
||||
<array>
|
||||
<integer>5</integer>
|
||||
</array>
|
||||
<key>IBSystem Version</key>
|
||||
<string>8H14</string>
|
||||
<key>IBUsesTextArchiving</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
2217
AppKit/English.lproj/NSToolbarCustomizationPalette.nib/keyedobjects.nib
generated
Normal file
2217
AppKit/English.lproj/NSToolbarCustomizationPalette.nib/keyedobjects.nib
generated
Normal file
File diff suppressed because it is too large
Load Diff
BIN
AppKit/English.lproj/NSToolbarCustomizationPalette.nib/objects.nib
generated
Normal file
BIN
AppKit/English.lproj/NSToolbarCustomizationPalette.nib/objects.nib
generated
Normal file
Binary file not shown.
24
AppKit/Info.plist
Normal file
24
AppKit/Info.plist
Normal file
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>English</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>AppKit</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string></string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>org.cocotron.AppKit</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>OBJC</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.0</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string></string>
|
||||
</dict>
|
||||
</plist>
|
18
AppKit/NSActionCell.h
Executable file
18
AppKit/NSActionCell.h
Executable file
@ -0,0 +1,18 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/NSCell.h>
|
||||
|
||||
@interface NSActionCell : NSCell {
|
||||
NSView *_controlView;
|
||||
id _target;
|
||||
SEL _action;
|
||||
int _tag;
|
||||
}
|
||||
|
||||
@end
|
62
AppKit/NSActionCell.m
Executable file
62
AppKit/NSActionCell.m
Executable file
@ -0,0 +1,62 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/NSActionCell.h>
|
||||
#import <AppKit/NSNibKeyedUnarchiver.h>
|
||||
|
||||
@implementation NSActionCell
|
||||
|
||||
-(void)encodeWithCoder:(NSCoder *)coder {
|
||||
[super encodeWithCoder:coder];
|
||||
[coder encodeInt:_tag forKey:@"NSActionCell tag"];
|
||||
}
|
||||
|
||||
-initWithCoder:(NSCoder *)coder {
|
||||
[super initWithCoder:coder];
|
||||
|
||||
if([coder isKindOfClass:[NSNibKeyedUnarchiver class]]){
|
||||
NSNibKeyedUnarchiver *keyed=(NSNibKeyedUnarchiver *)coder;
|
||||
|
||||
_tag=[keyed decodeIntForKey:@"NSTag"];
|
||||
}
|
||||
else {
|
||||
_tag=[coder decodeIntForKey:@"NSActionCell tag"];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(NSView *)controlView {
|
||||
return _controlView;
|
||||
}
|
||||
|
||||
-target {
|
||||
return _target;
|
||||
}
|
||||
|
||||
-(void)setTarget:target {
|
||||
_target=target;
|
||||
}
|
||||
|
||||
-(SEL)action {
|
||||
return _action;
|
||||
}
|
||||
|
||||
-(void)setAction:(SEL)action {
|
||||
_action=action;
|
||||
}
|
||||
|
||||
-(int)tag {
|
||||
return _tag;
|
||||
}
|
||||
|
||||
-(void)setTag:(int)tag {
|
||||
_tag=tag;
|
||||
}
|
||||
|
||||
@end
|
41
AppKit/NSAffineTransform.h
Executable file
41
AppKit/NSAffineTransform.h
Executable file
@ -0,0 +1,41 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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 <Foundation/NSGeometry.h>
|
||||
|
||||
typedef struct {
|
||||
float m11;
|
||||
float m12;
|
||||
float m21;
|
||||
float m22;
|
||||
float tX;
|
||||
float tY;
|
||||
} NSAffineTransformStruct;
|
||||
|
||||
@interface NSAffineTransform : NSObject <NSCopying> {
|
||||
NSAffineTransformStruct _matrix;
|
||||
}
|
||||
|
||||
-initWithTransform:(NSAffineTransform *)other;
|
||||
|
||||
+(NSAffineTransform *)transform;
|
||||
|
||||
-(NSAffineTransformStruct)transformStruct;
|
||||
-(void)setTransformStruct:(NSAffineTransformStruct)matrix;
|
||||
|
||||
-(void)invert;
|
||||
|
||||
-(void)appendTransform:(NSAffineTransform *)other;
|
||||
-(void)prependTransform:(NSAffineTransform *)other;
|
||||
|
||||
-(void)translateXBy:(float)xby yBy:(float)yby;
|
||||
|
||||
-(NSPoint)transformPoint:(NSPoint)point;
|
||||
|
||||
|
||||
@end
|
100
AppKit/NSAffineTransform.m
Executable file
100
AppKit/NSAffineTransform.m
Executable file
@ -0,0 +1,100 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/NSAffineTransform.h>
|
||||
|
||||
@implementation NSAffineTransform
|
||||
|
||||
static inline NSAffineTransformStruct multiplyStruct(NSAffineTransformStruct start, NSAffineTransformStruct append){
|
||||
NSAffineTransformStruct result;
|
||||
|
||||
result.m11=append.m11*start.m11+append.m12*start.m21;
|
||||
result.m12=append.m11*start.m12+append.m12*start.m22;
|
||||
result.m21=append.m21*start.m11+append.m22*start.m21;
|
||||
result.m22=append.m21*start.m12+append.m22*start.m22;
|
||||
result.tX=append.tX*start.m11+append.tY*start.m21+start.tX;
|
||||
result.tY=append.tX*start.m12+append.tY*start.m22+start.tY;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline NSAffineTransformStruct invertStruct(NSAffineTransformStruct matrix){
|
||||
NSAffineTransformStruct result;
|
||||
float determinant;
|
||||
|
||||
determinant=matrix.m11*matrix.m22-matrix.m21*matrix.m12;
|
||||
|
||||
result.m11=matrix.m22/determinant;
|
||||
result.m12=-matrix.m12/determinant;
|
||||
result.m21=-matrix.m21/determinant;
|
||||
result.m22=matrix.m11/determinant;
|
||||
result.tX=(-matrix.m22*matrix.tX+matrix.m21*matrix.tY)/determinant;
|
||||
result.tY=(matrix.m12*matrix.tX-matrix.m11*matrix.tY)/determinant;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
-init {
|
||||
_matrix.m11=1;
|
||||
_matrix.m12=0;
|
||||
_matrix.m21=0;
|
||||
_matrix.m22=1;
|
||||
_matrix.tX=0;
|
||||
_matrix.tY=0;
|
||||
return self;
|
||||
}
|
||||
|
||||
-initWithTransform:(NSAffineTransform *)other {
|
||||
_matrix=[other transformStruct];
|
||||
return self;
|
||||
}
|
||||
|
||||
-copyWithZone:(NSZone *)zone {
|
||||
return [[NSAffineTransform alloc] initWithTransform:self];
|
||||
}
|
||||
|
||||
+(NSAffineTransform *)transform {
|
||||
return [[self new] autorelease];
|
||||
}
|
||||
|
||||
-(NSAffineTransformStruct)transformStruct {
|
||||
return _matrix;
|
||||
}
|
||||
|
||||
-(void)setTransformStruct:(NSAffineTransformStruct)matrix {
|
||||
_matrix=matrix;
|
||||
}
|
||||
|
||||
-(void)invert {
|
||||
_matrix=invertStruct(_matrix);
|
||||
}
|
||||
|
||||
-(void)appendTransform:(NSAffineTransform *)other {
|
||||
_matrix=multiplyStruct(_matrix,[other transformStruct]);
|
||||
}
|
||||
|
||||
-(void)prependTransform:(NSAffineTransform *)other {
|
||||
_matrix=multiplyStruct([other transformStruct],_matrix);
|
||||
}
|
||||
|
||||
-(void)translateXBy:(float)xby yBy:(float)yby {
|
||||
NSAffineTransformStruct translate={1,0,0,1,xby,yby};
|
||||
_matrix=multiplyStruct(_matrix,translate);
|
||||
}
|
||||
|
||||
-(NSPoint)transformPoint:(NSPoint)point {
|
||||
NSPoint result;
|
||||
|
||||
result.x=_matrix.m11*point.x+_matrix.m21*point.y+_matrix.tX;
|
||||
result.y=_matrix.m12*point.x+_matrix.m22*point.y+_matrix.tY;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@end
|
22
AppKit/NSAlertPanel.h
Executable file
22
AppKit/NSAlertPanel.h
Executable file
@ -0,0 +1,22 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/NSPanel.h>
|
||||
|
||||
@class NSTextField,NSButton;
|
||||
|
||||
@interface NSAlertPanel : NSPanel {
|
||||
NSTextField *_messageText;
|
||||
NSButton *_defaultButton;
|
||||
NSButton *_alternateButton;
|
||||
NSButton *_otherButton;
|
||||
}
|
||||
|
||||
-initWithTitle:(NSString *)title message:(NSString *)message defaultButton:(NSString *)defaulteTitle alternateButton:(NSString *)alternateTitle otherButton:(NSString *)otherTitle sheet:(BOOL)sheet;
|
||||
|
||||
@end
|
197
AppKit/NSAlertPanel.m
Executable file
197
AppKit/NSAlertPanel.m
Executable file
@ -0,0 +1,197 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/NSAlertPanel.h>
|
||||
#import <AppKit/NSStringDrawer.h>
|
||||
#import <AppKit/NSImage.h>
|
||||
#import <AppKit/NSApplication.h>
|
||||
#import <AppKit/NSButton.h>
|
||||
#import <AppKit/NSTextField.h>
|
||||
#import <AppKit/NSImageView.h>
|
||||
|
||||
@implementation NSAlertPanel
|
||||
|
||||
#define BOTTOM_MARGIN 16
|
||||
#define TOP_MARGIN 16
|
||||
#define LEFT_MARGIN 16
|
||||
#define RIGHT_MARGIN 16
|
||||
#define BUTTONMESSAGE_GAP 20
|
||||
#define INTERBUTTON_GAP 6
|
||||
#define IMAGEMESSAGE_GAP 12
|
||||
#define BUTTON_MARGIN 8
|
||||
|
||||
-initWithTitle:(NSString *)title message:(NSString *)message defaultButton:(NSString *)defaultTitle alternateButton:(NSString *)alternateTitle otherButton:(NSString *)otherTitle sheet:(BOOL)sheet {
|
||||
NSImage *image=[NSImage imageNamed:@"NSAlertPanelExclamation"];
|
||||
NSSize imageSize=[image size];
|
||||
NSSize size={640,480};
|
||||
NSStringDrawer *drawer=[[[NSStringDrawer alloc] initWithSize:size] autorelease];
|
||||
NSSize messageSize=[drawer sizeOfString:message withAttributes:nil];
|
||||
NSSize defaultSize,alternateSize,otherSize;
|
||||
NSSize imageMessageSize=NSZeroSize;
|
||||
float buttonWidth,buttonHeight,buttonTotalWidth,buttonTotalHeight;
|
||||
NSSize panelSize=NSZeroSize;
|
||||
NSRect contentRect,viewFrame;
|
||||
NSImageView *imageView;
|
||||
|
||||
if(defaultTitle==nil)
|
||||
defaultTitle=@"OK";
|
||||
|
||||
defaultSize=[drawer sizeOfString:defaultTitle withAttributes:nil];
|
||||
buttonWidth=defaultSize.width;
|
||||
buttonHeight=defaultSize.height;
|
||||
|
||||
if(alternateTitle==nil)
|
||||
alternateSize=NSZeroSize;
|
||||
else {
|
||||
alternateSize=[drawer sizeOfString:alternateTitle withAttributes:nil];
|
||||
buttonWidth=MAX(alternateSize.width,buttonWidth);
|
||||
buttonHeight=MAX(alternateSize.height,buttonHeight);
|
||||
}
|
||||
|
||||
if(otherTitle==nil)
|
||||
otherSize=NSZeroSize;
|
||||
else {
|
||||
otherSize=[drawer sizeOfString:otherTitle withAttributes:nil];
|
||||
buttonWidth=MAX(otherSize.width,buttonWidth);
|
||||
buttonHeight=MAX(otherSize.height,buttonHeight);
|
||||
}
|
||||
|
||||
buttonWidth+=BUTTON_MARGIN*2;
|
||||
buttonWidth=MAX(66,buttonWidth);
|
||||
|
||||
buttonTotalWidth=LEFT_MARGIN;
|
||||
buttonTotalWidth+=buttonWidth;
|
||||
if(alternateTitle!=nil){
|
||||
buttonTotalWidth+=INTERBUTTON_GAP;
|
||||
buttonTotalWidth+=buttonWidth;
|
||||
}
|
||||
if(otherTitle!=nil){
|
||||
buttonTotalWidth+=INTERBUTTON_GAP;
|
||||
buttonTotalWidth+=buttonWidth;
|
||||
}
|
||||
buttonTotalWidth+=RIGHT_MARGIN;
|
||||
|
||||
if(buttonHeight<24)
|
||||
buttonHeight=24;
|
||||
if(buttonHeight>24)
|
||||
buttonHeight+=12;
|
||||
|
||||
buttonTotalHeight=BOTTOM_MARGIN+buttonHeight+BUTTONMESSAGE_GAP;
|
||||
|
||||
imageMessageSize.width+=LEFT_MARGIN;
|
||||
imageMessageSize.width+=imageSize.width;
|
||||
imageMessageSize.width+=IMAGEMESSAGE_GAP;
|
||||
imageMessageSize.width+=messageSize.width;
|
||||
imageMessageSize.width+=RIGHT_MARGIN;
|
||||
imageMessageSize.height=MAX(imageSize.height,messageSize.height);
|
||||
imageMessageSize.height+=TOP_MARGIN;
|
||||
|
||||
panelSize.width=MAX(imageMessageSize.width,buttonTotalWidth);
|
||||
panelSize.height=imageMessageSize.height+buttonTotalHeight;
|
||||
|
||||
contentRect.origin=NSZeroPoint;
|
||||
contentRect.size=panelSize;
|
||||
|
||||
self=[self initWithContentRect:contentRect styleMask:sheet?NSDocModalWindowMask:NSTitledWindowMask|NSClosableWindowMask backing:NSBackingStoreBuffered defer:NO];
|
||||
|
||||
if([title length]==0)
|
||||
title=@"Alert";
|
||||
|
||||
[self setTitle:title];
|
||||
|
||||
viewFrame.origin.y=BOTTOM_MARGIN;
|
||||
viewFrame.origin.x=LEFT_MARGIN+floor((panelSize.width-buttonTotalWidth)/2);
|
||||
viewFrame.size.width=buttonWidth;
|
||||
viewFrame.size.height=buttonHeight;
|
||||
_defaultButton=[[[NSButton alloc] initWithFrame:viewFrame] autorelease];
|
||||
[_defaultButton setTitle:defaultTitle];
|
||||
[_defaultButton setTarget:self];
|
||||
[_defaultButton setAction:@selector(defaultButton:)];
|
||||
[[self contentView] addSubview:_defaultButton];
|
||||
[self setInitialFirstResponder:_defaultButton];
|
||||
[self setDefaultButtonCell:[_defaultButton cell]];
|
||||
|
||||
if(alternateTitle!=nil){
|
||||
viewFrame.origin.x+=viewFrame.size.width;
|
||||
viewFrame.origin.x+=INTERBUTTON_GAP;
|
||||
viewFrame.size.width=buttonWidth;
|
||||
viewFrame.size.height=buttonHeight;
|
||||
_alternateButton=[[[NSButton alloc] initWithFrame:viewFrame] autorelease];
|
||||
[_alternateButton setTitle:alternateTitle];
|
||||
[_alternateButton setTarget:self];
|
||||
[_alternateButton setAction:@selector(alternateButton:)];
|
||||
[[self contentView] addSubview:_alternateButton];
|
||||
[_defaultButton setNextKeyView:_alternateButton];
|
||||
}
|
||||
|
||||
if(otherTitle!=nil){
|
||||
viewFrame.origin.x+=viewFrame.size.width;
|
||||
viewFrame.origin.x+=INTERBUTTON_GAP;
|
||||
viewFrame.size.width=buttonWidth;
|
||||
viewFrame.size.height=buttonHeight;
|
||||
_otherButton=[[[NSButton alloc] initWithFrame:viewFrame] autorelease];
|
||||
[_otherButton setTitle:otherTitle];
|
||||
[_otherButton setTarget:self];
|
||||
[_otherButton setAction:@selector(otherButton:)];
|
||||
[[self contentView] addSubview:_otherButton];
|
||||
[_alternateButton setNextKeyView:_otherButton];
|
||||
[_otherButton setNextKeyView:_defaultButton];
|
||||
}
|
||||
|
||||
viewFrame.origin.x=LEFT_MARGIN;
|
||||
viewFrame.origin.y+=viewFrame.size.height;
|
||||
viewFrame.origin.y+=BUTTONMESSAGE_GAP;
|
||||
if(messageSize.height>imageSize.height)
|
||||
viewFrame.origin.y+=messageSize.height-imageSize.height;
|
||||
viewFrame.size=imageSize;
|
||||
imageView=[[[NSImageView alloc] initWithFrame:viewFrame] autorelease];
|
||||
[imageView setImage:image];
|
||||
[[self contentView] addSubview:imageView];
|
||||
|
||||
viewFrame.origin.x+=imageSize.width;
|
||||
viewFrame.origin.x+=IMAGEMESSAGE_GAP;
|
||||
viewFrame.origin.y-=messageSize.height-imageSize.height;
|
||||
viewFrame.size=messageSize;
|
||||
_messageText=[[[NSTextField alloc] initWithFrame:viewFrame] autorelease];
|
||||
[_messageText setStringValue:message];
|
||||
[_messageText setSelectable:YES];
|
||||
[_messageText setBordered:NO];
|
||||
[[self contentView] addSubview:_messageText];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)defaultButton:sender {
|
||||
if([self isSheet])
|
||||
[NSApp endSheet:self returnCode:NSAlertDefaultReturn];
|
||||
else
|
||||
[NSApp stopModalWithCode:NSAlertDefaultReturn];
|
||||
|
||||
[self close];
|
||||
}
|
||||
|
||||
-(void)alternateButton:sender {
|
||||
if([self isSheet])
|
||||
[NSApp endSheet:self returnCode:NSAlertAlternateReturn];
|
||||
else
|
||||
[NSApp stopModalWithCode:NSAlertAlternateReturn];
|
||||
|
||||
[self close];
|
||||
}
|
||||
|
||||
-(void)otherButton:sender {
|
||||
if([self isSheet])
|
||||
[NSApp endSheet:self returnCode:NSAlertOtherReturn];
|
||||
else
|
||||
[NSApp stopModalWithCode:NSAlertOtherReturn];
|
||||
|
||||
[self close];
|
||||
}
|
||||
|
||||
@end
|
BIN
AppKit/NSAlertPanelExclamation.tiff
Executable file
BIN
AppKit/NSAlertPanelExclamation.tiff
Executable file
Binary file not shown.
147
AppKit/NSApplication.h
Executable file
147
AppKit/NSApplication.h
Executable file
@ -0,0 +1,147 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/NSResponder.h>
|
||||
#import <AppKit/AppKitExport.h>
|
||||
|
||||
@class NSWindow,NSImage,NSMenu, NSPasteboard, NSDisplay;
|
||||
|
||||
APPKIT_EXPORT NSString *NSModalPanelRunLoopMode;
|
||||
APPKIT_EXPORT NSString *NSEventTrackingRunLoopMode;
|
||||
|
||||
APPKIT_EXPORT NSString *NSApplicationWillFinishLaunchingNotification;
|
||||
APPKIT_EXPORT NSString *NSApplicationDidFinishLaunchingNotification;
|
||||
|
||||
APPKIT_EXPORT NSString *NSApplicationDidBecomeActiveNotification;
|
||||
APPKIT_EXPORT NSString *NSApplicationWillResignActiveNotification;
|
||||
|
||||
APPKIT_EXPORT id NSApp;
|
||||
|
||||
typedef id NSModalSession;
|
||||
|
||||
enum {
|
||||
NSRunStoppedResponse=-1000,
|
||||
NSRunAbortedResponse=-1001,
|
||||
NSRunContinuesResponse=-1002
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
NSTerminateCancel,
|
||||
NSTerminateNow,
|
||||
} NSApplicationTerminateReply;
|
||||
|
||||
|
||||
@interface NSApplication : NSResponder {
|
||||
NSDisplay *_display;
|
||||
id _delegate;
|
||||
NSMutableArray *_windows;
|
||||
NSMenu *_mainMenu;
|
||||
NSMenu *_windowsMenu;
|
||||
|
||||
NSImage *_applicationIconImage;
|
||||
|
||||
BOOL _isActive;
|
||||
NSEvent *_currentEvent;
|
||||
|
||||
NSMutableArray *_modalStack;
|
||||
}
|
||||
|
||||
+(NSApplication *)sharedApplication;
|
||||
|
||||
-init;
|
||||
|
||||
-delegate;
|
||||
-(NSArray *)windows;
|
||||
-(NSMenu *)mainMenu;
|
||||
-(NSMenu *)windowsMenu;
|
||||
-(NSWindow *)mainWindow;
|
||||
-(NSWindow *)keyWindow;
|
||||
-(NSImage *)applicationIconImage;
|
||||
-(BOOL)isActive;
|
||||
|
||||
-(void)setDelegate:delegate;
|
||||
-(void)setMainMenu:(NSMenu *)menu;
|
||||
-(void)setApplicationIconImage:(NSImage *)image;
|
||||
|
||||
-(void)setWindowsMenu:(NSMenu *)menu;
|
||||
-(void)addWindowsItem:(NSWindow *)window title:(NSString *)title filename:(BOOL)filename;
|
||||
-(void)changeWindowsItem:(NSWindow *)window title:(NSString *)title filename:(BOOL)filename;
|
||||
-(void)removeWindowsItem:(NSWindow *)window;
|
||||
|
||||
-(void)finishLaunching;
|
||||
-(void)run;
|
||||
|
||||
-(void)sendEvent:(NSEvent *)event;
|
||||
|
||||
-(NSEvent *)nextEventMatchingMask:(unsigned int)mask untilDate:(NSDate *)untilDate inMode:(NSString *)mode dequeue:(BOOL)dequeue;
|
||||
-(NSEvent *)currentEvent;
|
||||
-(void)discardEventsMatchingMask:(unsigned)mask beforeEvent:(NSEvent *)event;
|
||||
-(void)postEvent:(NSEvent *)event atStart:(BOOL)atStart;
|
||||
|
||||
-targetForAction:(SEL)action;
|
||||
-(BOOL)sendAction:(SEL)action to:target from:sender;
|
||||
|
||||
-(void)updateWindows;
|
||||
|
||||
-(void)activateIgnoringOtherApps:(BOOL)flag;
|
||||
|
||||
-(NSWindow *)modalWindow;
|
||||
-(NSModalSession)beginModalSessionForWindow:(NSWindow *)window;
|
||||
-(int)runModalSession:(NSModalSession)session;
|
||||
-(void)endModalSession:(NSModalSession)session;
|
||||
-(void)stopModalWithCode:(int)code;
|
||||
|
||||
-(int)runModalForWindow:(NSWindow *)window;
|
||||
-(void)stopModal;
|
||||
-(void)abortModal;
|
||||
|
||||
-(void)beginSheet:(NSWindow *)sheet modalForWindow:(NSWindow *)window modalDelegate:modalDelegate didEndSelector:(SEL)didEndSelector contextInfo:(void *)contextInfo;
|
||||
-(void)endSheet:(NSWindow *)sheet returnCode:(int)returnCode;
|
||||
-(void)endSheet:(NSWindow *)sheet;
|
||||
|
||||
-(void)reportException:(NSException *)exception;
|
||||
|
||||
-(void)runPageLayout:sender;
|
||||
-(void)orderFrontColorPanel:sender;
|
||||
|
||||
-(void)hide:sender;
|
||||
-(void)unhide:sender;
|
||||
-(void)terminate:sender;
|
||||
|
||||
-(void)arrangeInFront:sender;
|
||||
|
||||
-servicesProvider;
|
||||
-(void)setServicesProvider:provider;
|
||||
-(void)registerServicesMenuSendTypes:(NSArray *)sendTypes returnTypes:(NSArray *)returnTypes;
|
||||
|
||||
// private
|
||||
-(void)_addWindow:(NSWindow *)window;
|
||||
@end
|
||||
|
||||
@interface NSObject(NSApplication_serviceRequest)
|
||||
-(BOOL)writeSelectionToPasteboard:(NSPasteboard *)pasteboard types:(NSArray *)types;
|
||||
@end
|
||||
|
||||
@interface NSObject(NSApplication_notifications)
|
||||
-(void)applicationWillFinishLaunching:(NSNotification *)note;
|
||||
-(void)applicationDidFinishLaunching:(NSNotification *)note;
|
||||
-(void)applicationDidBecomeActive:(NSNotification *)note;
|
||||
@end
|
||||
|
||||
@interface NSObject(NSApplication_delegate)
|
||||
-(BOOL)application:sender openFile:(NSString *)path;
|
||||
-(BOOL)application:sender openTempFile:(NSString *)path;
|
||||
-(NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)application;
|
||||
@end
|
||||
|
||||
APPKIT_EXPORT int NSApplicationMain(int argc, const char *argv[]);
|
||||
|
||||
APPKIT_EXPORT void NSUpdateDynamicServices(void);
|
||||
APPKIT_EXPORT BOOL NSPerformService(NSString *itemName, NSPasteboard *pasteboard);
|
||||
|
||||
|
719
AppKit/NSApplication.m
Executable file
719
AppKit/NSApplication.m
Executable file
@ -0,0 +1,719 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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. */
|
||||
|
||||
// "Window" menu - David Young <daver@geeks.org>
|
||||
// Original - Christopher Lloyd <cjwl@objc.net>
|
||||
#import <AppKit/NSApplication.h>
|
||||
#import <AppKit/NSWindow-Private.h>
|
||||
#import <AppKit/NSPanel.h>
|
||||
#import <AppKit/NSMenu.h>
|
||||
#import <AppKit/NSMenuItem.h>
|
||||
#import <AppKit/NSEvent.h>
|
||||
#import <AppKit/NSModalSessionX.h>
|
||||
#import <AppKit/NSNibLoading.h>
|
||||
#import <AppKit/NSScreen.h>
|
||||
#import <AppKit/NSColorPanel.h>
|
||||
#import <AppKit/NSDisplay.h>
|
||||
#import <AppKit/NSPageLayout.h>
|
||||
#import <AppKit/NSPlatform.h>
|
||||
#import <AppKit/NSDocumentController.h>
|
||||
#import <AppKit/NSSheetContext.h>
|
||||
|
||||
NSString *NSModalPanelRunLoopMode=@"NSModalPanelRunLoopMode";
|
||||
NSString *NSEventTrackingRunLoopMode=@"NSEventTrackingRunLoopMode";
|
||||
|
||||
NSString *NSApplicationWillFinishLaunchingNotification=@"NSApplicationWillFinishLaunchingNotification";
|
||||
NSString *NSApplicationDidFinishLaunchingNotification=@"NSApplicationDidFinishLaunchingNotification";
|
||||
|
||||
NSString *NSApplicationDidBecomeActiveNotification=@"NSApplicationDidBecomeActiveNotification";
|
||||
NSString *NSApplicationWillResignActiveNotification=@"NSApplicationWillResignActiveNotification";
|
||||
|
||||
@implementation NSApplication
|
||||
|
||||
id NSApp=nil;
|
||||
|
||||
+(void)initialize {
|
||||
if(self==[NSApplication class]){
|
||||
Win32UseRunningCopyOfApplication();
|
||||
}
|
||||
}
|
||||
|
||||
+(NSApplication *)sharedApplication {
|
||||
|
||||
if(NSApp==nil){
|
||||
NSApp=[self alloc]; // NSApp must be valid inside init
|
||||
NSApp=[NSApp init];
|
||||
}
|
||||
|
||||
return NSApp;
|
||||
}
|
||||
|
||||
-init {
|
||||
_display=[[NSDisplay currentDisplay] retain];
|
||||
[_display showSplashImage];
|
||||
|
||||
_windows=[NSMutableArray new];
|
||||
_mainMenu=nil;
|
||||
|
||||
_modalStack=[NSMutableArray new];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
-delegate {
|
||||
return _delegate;
|
||||
}
|
||||
|
||||
-(NSArray *)windows {
|
||||
return _windows;
|
||||
}
|
||||
|
||||
-(NSMenu *)mainMenu {
|
||||
return _mainMenu;
|
||||
}
|
||||
|
||||
-(NSMenu *)menu {
|
||||
return [self mainMenu];
|
||||
}
|
||||
|
||||
// FIX should be a better way to determine this... IB? special tags?
|
||||
/* This info is in the NSMenuTemplate? */
|
||||
|
||||
-(NSMenu *)windowsMenu {
|
||||
#if 1
|
||||
if(_windowsMenu==nil)
|
||||
_windowsMenu=[[[[self mainMenu] itemWithTitle:@"Window"] submenu] retain];
|
||||
if(_windowsMenu==nil) // Some apps use "Windows"
|
||||
_windowsMenu=[[[[self mainMenu] itemWithTitle:@"Windows"] submenu] retain];
|
||||
|
||||
#endif
|
||||
return _windowsMenu;
|
||||
}
|
||||
|
||||
-(NSWindow *)mainWindow {
|
||||
int i,count=[_windows count];
|
||||
|
||||
for(i=0;i<count;i++)
|
||||
if([[_windows objectAtIndex:i] isMainWindow])
|
||||
return [_windows objectAtIndex:i];
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
-(NSWindow *)keyWindow {
|
||||
int i,count=[_windows count];
|
||||
|
||||
for(i=0;i<count;i++)
|
||||
if([[_windows objectAtIndex:i] isKeyWindow])
|
||||
return [_windows objectAtIndex:i];
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
-(NSImage *)applicationIconImage {
|
||||
NSUnimplementedMethod();
|
||||
return nil;
|
||||
}
|
||||
|
||||
-(BOOL)isActive {
|
||||
int count=[_windows count];
|
||||
|
||||
while(--count>=0){
|
||||
NSWindow *check=[_windows objectAtIndex:count];
|
||||
|
||||
if([check _isActive])
|
||||
return YES;
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
-(void)registerDelegate {
|
||||
if([_delegate respondsToSelector:@selector(applicationWillFinishLaunching:)]){
|
||||
[[NSNotificationCenter defaultCenter] addObserver:_delegate
|
||||
selector:@selector(applicationWillFinishLaunching:)
|
||||
name:NSApplicationWillFinishLaunchingNotification object:self];
|
||||
}
|
||||
if([_delegate respondsToSelector:@selector(applicationDidFinishLaunching:)]){
|
||||
[[NSNotificationCenter defaultCenter] addObserver:_delegate
|
||||
selector:@selector(applicationDidFinishLaunching:)
|
||||
name:NSApplicationDidFinishLaunchingNotification object:self];
|
||||
}
|
||||
if([_delegate respondsToSelector:@selector(applicationDidBecomeActive:)]){
|
||||
[[NSNotificationCenter defaultCenter] addObserver:_delegate
|
||||
selector:@selector(applicationDidBecomeActive:)
|
||||
name: NSApplicationDidBecomeActiveNotification object:self];
|
||||
}
|
||||
}
|
||||
|
||||
-(void)setDelegate:delegate {
|
||||
_delegate=delegate;
|
||||
[self registerDelegate];
|
||||
}
|
||||
|
||||
-(void)setMainMenu:(NSMenu *)menu {
|
||||
int i,count=[_windows count];
|
||||
|
||||
[_mainMenu autorelease];
|
||||
_mainMenu=[menu copy];
|
||||
|
||||
for(i=0;i<count;i++){
|
||||
NSWindow *window=[_windows objectAtIndex:i];
|
||||
|
||||
if(![window isKindOfClass:[NSPanel class]])
|
||||
[window setMenu:_mainMenu];
|
||||
}
|
||||
}
|
||||
|
||||
-(void)setMenu:(NSMenu *)menu {
|
||||
[self setMainMenu:menu];
|
||||
}
|
||||
|
||||
-(void)setApplicationIconImage:(NSImage *)image {
|
||||
NSUnimplementedMethod();
|
||||
}
|
||||
|
||||
-(void)setWindowsMenu:(NSMenu *)menu {
|
||||
//NSLog(@"%s %@",SELNAME(_cmd),menu);
|
||||
[_windowsMenu autorelease];
|
||||
_windowsMenu=[menu retain];
|
||||
}
|
||||
|
||||
-(void)addWindowsItem:(NSWindow *)window title:(NSString *)title filename:(BOOL)isFilename {
|
||||
NSMenuItem *windowItem;
|
||||
|
||||
if ([[self windowsMenu] indexOfItemWithTarget:window andAction:@selector(makeKeyAndOrderFront:)] != -1)
|
||||
return;
|
||||
|
||||
// separator management... shouldn't +separatorItem be a singleton? i dunno..
|
||||
// e.g. here, lastObject] == [NSMenuItem separatorItem] ?
|
||||
windowItem = [[[self windowsMenu] itemArray] lastObject];
|
||||
if ([windowItem title] != nil && ![[windowItem target] isKindOfClass:[NSWindow class]])
|
||||
[[self windowsMenu] addItem:[NSMenuItem separatorItem]];
|
||||
|
||||
if (isFilename)
|
||||
title = [NSString stringWithFormat:@"%@ -- %@", [title lastPathComponent],
|
||||
[title stringByDeletingLastPathComponent]];
|
||||
|
||||
windowItem = [[[NSMenuItem alloc] initWithTitle:title
|
||||
action:@selector(makeKeyAndOrderFront:)
|
||||
keyEquivalent:@""] autorelease];
|
||||
[windowItem setTarget:window];
|
||||
|
||||
[[self windowsMenu] addItem:windowItem];
|
||||
//NSLog(@"add: %@ %@ %@", [self windowsMenu], title, windowItem);
|
||||
}
|
||||
|
||||
-(void)changeWindowsItem:(NSWindow *)window title:(NSString *)title filename:(BOOL)isFilename {
|
||||
int itemIndex = [[self windowsMenu] indexOfItemWithTarget:window
|
||||
andAction:@selector(makeKeyAndOrderFront:)];
|
||||
|
||||
if (itemIndex != -1) {
|
||||
NSMenuItem *windowItem = [[self windowsMenu] itemAtIndex:itemIndex];
|
||||
|
||||
if (isFilename)
|
||||
title = [NSString stringWithFormat:@"%@ -- %@",
|
||||
[title lastPathComponent], [title stringByDeletingLastPathComponent]];
|
||||
|
||||
[windowItem setTitle:title];
|
||||
[[self windowsMenu] itemChanged:windowItem];
|
||||
}
|
||||
else
|
||||
[self addWindowsItem:window title:title filename:isFilename];
|
||||
}
|
||||
|
||||
-(void)removeWindowsItem:(NSWindow *)window {
|
||||
int itemIndex = [[self windowsMenu] indexOfItemWithTarget:window
|
||||
andAction:@selector(makeKeyAndOrderFront:)];
|
||||
if (itemIndex != -1) {
|
||||
[[self windowsMenu] removeItemAtIndex:itemIndex];
|
||||
|
||||
// separator
|
||||
if ([[[[self windowsMenu] itemArray] lastObject] title] == nil)
|
||||
[[self windowsMenu] removeItem:[[[self windowsMenu] itemArray] lastObject]];
|
||||
}
|
||||
}
|
||||
|
||||
-(void)finishLaunching {
|
||||
NSAutoreleasePool *pool=[NSAutoreleasePool new];
|
||||
BOOL needsUntitled=YES;
|
||||
|
||||
NS_DURING
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName: NSApplicationWillFinishLaunchingNotification object:self];
|
||||
NS_HANDLER
|
||||
[self reportException:localException];
|
||||
NS_ENDHANDLER
|
||||
|
||||
// Give us a first event
|
||||
[NSTimer scheduledTimerWithTimeInterval:0.1 target:nil
|
||||
selector:NULL userInfo:nil repeats:NO];
|
||||
|
||||
[_display closeSplashImage];
|
||||
|
||||
if(_delegate==nil){
|
||||
id types=[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDocumentTypes"];
|
||||
|
||||
if([types count]>0)
|
||||
_delegate=[NSDocumentController sharedDocumentController];
|
||||
}
|
||||
|
||||
if([_delegate respondsToSelector:@selector(application:openFile:)]){
|
||||
NSString *openFile=[[NSUserDefaults standardUserDefaults] stringForKey:@"NSOpen"];
|
||||
|
||||
if([openFile length]>0){
|
||||
if([_delegate application:self openFile:openFile])
|
||||
needsUntitled=NO;
|
||||
}
|
||||
}
|
||||
|
||||
if(needsUntitled && [_delegate isKindOfClass:[NSDocumentController class]])
|
||||
[_delegate newDocument:self];
|
||||
|
||||
NS_DURING
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:NSApplicationDidFinishLaunchingNotification object:self];
|
||||
NS_HANDLER
|
||||
[self reportException:localException];
|
||||
NS_ENDHANDLER
|
||||
|
||||
[pool release];
|
||||
}
|
||||
|
||||
-(void)_checkForReleasedWindows {
|
||||
int count=[_windows count];
|
||||
|
||||
while(--count>=0){
|
||||
NSWindow *check=[_windows objectAtIndex:count];
|
||||
|
||||
if([check retainCount]==1)
|
||||
[_windows removeObjectAtIndex:count];
|
||||
}
|
||||
}
|
||||
|
||||
-(void)_checkForTerminate {
|
||||
int count=[_windows count];
|
||||
|
||||
while(--count>=0){
|
||||
NSWindow *check=[_windows objectAtIndex:count];
|
||||
|
||||
if(![check isKindOfClass:[NSPanel class]] && [check isVisible]){
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
[self terminate:self];
|
||||
}
|
||||
|
||||
-(void)_checkForAppActivation {
|
||||
#if 1
|
||||
if([self isActive])
|
||||
[_windows makeObjectsPerformSelector:@selector(_showForActivation)];
|
||||
else
|
||||
[_windows makeObjectsPerformSelector:@selector(_hideForDeactivation)];
|
||||
#endif
|
||||
}
|
||||
|
||||
-(void)run {
|
||||
|
||||
[self finishLaunching];
|
||||
|
||||
do {
|
||||
NSAutoreleasePool *pool=[NSAutoreleasePool new];
|
||||
NSEvent *event;
|
||||
|
||||
//OBJCReportStatistics();
|
||||
|
||||
event=[self nextEventMatchingMask:NSAnyEventMask
|
||||
untilDate:[NSDate distantFuture] inMode:NSDefaultRunLoopMode dequeue:YES];
|
||||
|
||||
NS_DURING
|
||||
[self sendEvent:event];
|
||||
|
||||
NS_HANDLER
|
||||
[self reportException:localException];
|
||||
NS_ENDHANDLER
|
||||
|
||||
[self _checkForReleasedWindows];
|
||||
[self _checkForTerminate];
|
||||
|
||||
[pool release];
|
||||
}while(YES);
|
||||
}
|
||||
|
||||
-(BOOL)_performKeyEquivalent:(NSEvent *)event {
|
||||
if([[self mainMenu] performKeyEquivalent:event])
|
||||
return YES;
|
||||
if([[self keyWindow] performKeyEquivalent:event])
|
||||
return YES;
|
||||
if([[self mainWindow] performKeyEquivalent:event])
|
||||
return YES;
|
||||
// documentation says to send it to all windows
|
||||
return NO;
|
||||
}
|
||||
|
||||
-(void)sendEvent:(NSEvent *)event {
|
||||
if([event type]==NSKeyDown){
|
||||
unsigned modifierFlags=[event modifierFlags];
|
||||
|
||||
if(modifierFlags&(NSCommandKeyMask|NSAlternateKeyMask))
|
||||
if([self _performKeyEquivalent:event])
|
||||
return;
|
||||
}
|
||||
|
||||
[[event window] sendEvent:event];
|
||||
}
|
||||
|
||||
-(NSEvent *)nextEventMatchingMask:(unsigned int)mask untilDate:(NSDate *)untilDate inMode:(NSString *)mode dequeue:(BOOL)dequeue {
|
||||
NSAutoreleasePool *pool=[NSAutoreleasePool new];
|
||||
NSEvent *nextEvent;
|
||||
|
||||
NS_DURING
|
||||
[NSClassFromString(@"Win32RunningCopyPipe") performSelector:@selector(createRunningCopyPipe)];
|
||||
[[NSApp windows] makeObjectsPerformSelector:@selector(_makeSureIsOnAScreen)];
|
||||
|
||||
[self _checkForReleasedWindows];
|
||||
[self _checkForAppActivation];
|
||||
[[NSApp windows] makeObjectsPerformSelector:@selector(displayIfNeeded)];
|
||||
|
||||
nextEvent=[_display nextEventMatchingMask:mask untilDate:untilDate inMode:mode dequeue:dequeue];
|
||||
|
||||
[_currentEvent release];
|
||||
_currentEvent=[nextEvent retain];
|
||||
|
||||
NS_HANDLER
|
||||
[self reportException:localException];
|
||||
NS_ENDHANDLER
|
||||
|
||||
[pool release];
|
||||
|
||||
return [[_currentEvent retain] autorelease];
|
||||
}
|
||||
|
||||
-(NSEvent *)currentEvent {
|
||||
return _currentEvent;
|
||||
}
|
||||
|
||||
-(void)discardEventsMatchingMask:(unsigned)mask beforeEvent:(NSEvent *)event {
|
||||
[_display discardEventsMatchingMask:mask beforeEvent:event];
|
||||
}
|
||||
|
||||
-(void)postEvent:(NSEvent *)event atStart:(BOOL)atStart {
|
||||
[_display postEvent:event atStart:atStart];
|
||||
}
|
||||
|
||||
-targetForAction:(SEL)action {
|
||||
NSWindow *window;
|
||||
NSResponder *check;
|
||||
|
||||
window=[self keyWindow];
|
||||
|
||||
for(check=[window firstResponder];check!=nil;check=[check nextResponder]){
|
||||
if([check respondsToSelector:action])
|
||||
return check;
|
||||
}
|
||||
|
||||
if([window respondsToSelector:action])
|
||||
return window;
|
||||
|
||||
if([[window delegate] respondsToSelector:action])
|
||||
return [window delegate];
|
||||
|
||||
window=[self mainWindow];
|
||||
|
||||
for(check=[window firstResponder];check!=nil;check=[check nextResponder]){
|
||||
if([check respondsToSelector:action])
|
||||
return check;
|
||||
}
|
||||
|
||||
if([window respondsToSelector:action])
|
||||
return window;
|
||||
|
||||
if([[window delegate] respondsToSelector:action])
|
||||
return [window delegate];
|
||||
|
||||
if([self respondsToSelector:action])
|
||||
return self;
|
||||
|
||||
if([[self delegate] respondsToSelector:action])
|
||||
return [self delegate];
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
-(BOOL)sendAction:(SEL)action to:target from:sender {
|
||||
|
||||
//NSLog(@"%s %s %@ %@",SELNAME(_cmd),action,target,sender);
|
||||
|
||||
if(target!=nil){
|
||||
if([target respondsToSelector:action]){
|
||||
[target performSelector:action withObject:sender];
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
else if((target=[self targetForAction:action])!=nil){
|
||||
[target performSelector:action withObject:sender];
|
||||
return YES;
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
-(void)updateWindows {
|
||||
[_windows makeObjectsPerformSelector:@selector(update)];
|
||||
}
|
||||
|
||||
-(void)activateIgnoringOtherApps:(BOOL)flag {
|
||||
NSUnimplementedMethod();
|
||||
}
|
||||
|
||||
-(NSWindow *)modalWindow {
|
||||
return [[_modalStack lastObject] modalWindow];
|
||||
}
|
||||
|
||||
-(NSModalSession)beginModalSessionForWindow:(NSWindow *)window {
|
||||
NSModalSessionX *session=[NSModalSessionX sessionWithWindow:window];
|
||||
|
||||
[_modalStack addObject:session];
|
||||
|
||||
[window center];
|
||||
[window makeKeyAndOrderFront:self];
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
-(int)runModalSession:(NSModalSession)session {
|
||||
NSAutoreleasePool *pool=[NSAutoreleasePool new];
|
||||
NSDate *future=[NSDate distantFuture];
|
||||
NSEvent *event=[self nextEventMatchingMask:NSAnyEventMask
|
||||
untilDate:future inMode:NSModalPanelRunLoopMode dequeue:YES];
|
||||
NSWindow *window=[event window];
|
||||
|
||||
// in theory this could get weird, but all we want is the ESC-cancel keybinding, afaik NSApp doesn't respond to any other doCommandBySelectors...
|
||||
if([event type]==NSKeyDown && window == [session modalWindow])
|
||||
[self interpretKeyEvents:[NSArray arrayWithObject:event]];
|
||||
|
||||
if(window==[session modalWindow] || [window worksWhenModal])
|
||||
[self sendEvent:event];
|
||||
else if([event type]==NSLeftMouseDown)
|
||||
[[session modalWindow] makeKeyAndOrderFront:self];
|
||||
|
||||
[pool release];
|
||||
|
||||
return [session stopCode];
|
||||
}
|
||||
|
||||
-(void)endModalSession:(NSModalSession)session {
|
||||
[_modalStack removeLastObject];
|
||||
}
|
||||
|
||||
-(void)stopModalWithCode:(int)code {
|
||||
if([_modalStack lastObject]==nil)
|
||||
[NSException raise:NSInvalidArgumentException
|
||||
format:@"-[%@ %s] no modal session running",isa,SELNAME(_cmd)];
|
||||
|
||||
[[_modalStack lastObject] stopModalWithCode:code];
|
||||
}
|
||||
|
||||
-(int)runModalForWindow:(NSWindow *)window {
|
||||
NSModalSession session=[self beginModalSessionForWindow:window];
|
||||
int result;
|
||||
|
||||
|
||||
while((result=[NSApp runModalSession:session])==NSRunContinuesResponse)
|
||||
;
|
||||
|
||||
[self endModalSession:session];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
-(void)stopModal {
|
||||
[self stopModalWithCode:NSRunStoppedResponse];
|
||||
}
|
||||
|
||||
-(void)abortModal {
|
||||
[self stopModalWithCode:NSRunAbortedResponse];
|
||||
}
|
||||
|
||||
// cancel modal windows
|
||||
-(void)cancel:sender {
|
||||
if ([self modalWindow] != nil)
|
||||
[self abortModal];
|
||||
}
|
||||
|
||||
-(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
|
||||
if ([sheet styleMask] != NSDocModalWindowMask)
|
||||
[sheet _setStyleMask:NSDocModalWindowMask];
|
||||
#endif
|
||||
// if ([sheet styleMask] != NSBorderlessWindowMask)
|
||||
// [sheet _setStyleMask:NSBorderlessWindowMask];
|
||||
|
||||
[window _attachSheetContextOrderFrontAndAnimate:context];
|
||||
}
|
||||
|
||||
-(void)endSheet:(NSWindow *)sheet returnCode:(int)returnCode {
|
||||
int count=[_windows count];
|
||||
|
||||
while(--count>=0){
|
||||
NSWindow *check=[_windows objectAtIndex:count];
|
||||
NSSheetContext *context=[check _sheetContext];
|
||||
IMP function;
|
||||
|
||||
if([context sheet]==sheet){
|
||||
[[context retain] autorelease];
|
||||
|
||||
[check _detachSheetContextAnimateAndOrderOut];
|
||||
|
||||
function=objc_msg_lookup([context modalDelegate],[context didEndSelector]);
|
||||
function([context modalDelegate],[context didEndSelector],sheet,returnCode,[context contextInfo]);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-(void)endSheet:(NSWindow *)sheet {
|
||||
[self endSheet:sheet returnCode:0];
|
||||
}
|
||||
|
||||
-(void)reportException:(NSException *)exception {
|
||||
NSLog(@"NSApplication got exception: %@",exception);
|
||||
}
|
||||
|
||||
-(void)runPageLayout:sender {
|
||||
[[NSPageLayout pageLayout] runModal];
|
||||
}
|
||||
|
||||
-(void)orderFrontColorPanel:(id)sender {
|
||||
[[NSColorPanel sharedColorPanel] orderFront:sender];
|
||||
}
|
||||
|
||||
-(void)hide:sender {
|
||||
NSUnimplementedMethod();
|
||||
}
|
||||
|
||||
-(void)unhide:sender {
|
||||
NSUnimplementedMethod();
|
||||
}
|
||||
|
||||
-(void)terminate:sender {
|
||||
if([_delegate respondsToSelector:@selector(applicationShouldTerminate:)]){
|
||||
if(![_delegate applicationShouldTerminate:self]){
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
[NSClassFromString(@"Win32RunningCopyPipe") performSelector:@selector(invalidateRunningCopyPipe)];
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
-(void)arrangeInFront:sender {
|
||||
#define CASCADE_DELTA 20 // ? isn't there a call for this?
|
||||
NSMutableArray *visibleWindows = [NSMutableArray new];
|
||||
NSRect rect=[[[NSScreen screens] objectAtIndex:0] frame], winRect;
|
||||
NSArray *windowsItems = [[self windowsMenu] itemArray];
|
||||
int i, count=[windowsItems count];
|
||||
|
||||
for (i = 0 ; i < count; ++i) {
|
||||
id target = [[windowsItems objectAtIndex:i] target];
|
||||
|
||||
if ([target isKindOfClass:[NSWindow class]])
|
||||
[visibleWindows addObject:target];
|
||||
}
|
||||
|
||||
count = [visibleWindows count];
|
||||
if (count == 0)
|
||||
return;
|
||||
|
||||
// find screen center.
|
||||
// subtract window w,h /2
|
||||
winRect = [[visibleWindows objectAtIndex:0] frame];
|
||||
rect.origin.x = (rect.size.width/2) - (winRect.size.width/2);
|
||||
rect.origin.x -= count*CASCADE_DELTA/2;
|
||||
rect.origin.x=floor(rect.origin.x);
|
||||
|
||||
rect.origin.y = (rect.size.height/2) + (winRect.size.height/2);
|
||||
rect.origin.y += count*CASCADE_DELTA/2;
|
||||
rect.origin.y=floor(rect.origin.y);
|
||||
|
||||
for (i = 0; i < count; ++i) {
|
||||
[[visibleWindows objectAtIndex:i] setFrameTopLeftPoint:rect.origin];
|
||||
[[visibleWindows objectAtIndex:i] orderFront:nil];
|
||||
|
||||
rect.origin.x += CASCADE_DELTA;
|
||||
rect.origin.y -= CASCADE_DELTA;
|
||||
}
|
||||
}
|
||||
|
||||
-(void)showHelp:sender {
|
||||
NSUnimplementedMethod();
|
||||
}
|
||||
|
||||
-servicesProvider {
|
||||
//NSUnsupportedMethod();
|
||||
return nil;
|
||||
}
|
||||
|
||||
-(void)setServicesProvider:provider {
|
||||
//NSUnsupportedMethod();
|
||||
}
|
||||
|
||||
-(void)registerServicesMenuSendTypes:(NSArray *)sendTypes returnTypes:(NSArray *)returnTypes {
|
||||
//tiredofthesewarnings NSUnsupportedMethod();
|
||||
}
|
||||
|
||||
- (void)doCommandBySelector:(SEL)selector {
|
||||
if ([_delegate respondsToSelector:selector])
|
||||
[_delegate performSelector:selector withObject:nil];
|
||||
else
|
||||
[super doCommandBySelector:selector];
|
||||
}
|
||||
|
||||
-(void)_addWindow:(NSWindow *)window {
|
||||
[_windows addObject:window];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
int NSApplicationMain(int argc, const char *argv[]) {
|
||||
NSInitializeProcess(__argc,(const char **)__argv);
|
||||
{
|
||||
NSAutoreleasePool *pool=[NSAutoreleasePool new];
|
||||
NSBundle *bundle=[NSBundle mainBundle];
|
||||
Class class=[bundle principalClass];
|
||||
NSString *nibFile=[[bundle infoDictionary] objectForKey:@"NSMainNibFile"];
|
||||
|
||||
if(class==Nil)
|
||||
class=[NSApplication class];
|
||||
|
||||
[class sharedApplication];
|
||||
|
||||
nibFile=[nibFile stringByDeletingPathExtension];
|
||||
|
||||
if(![NSBundle loadNibNamed:nibFile owner:NSApp])
|
||||
NSLog(@"Unable to load main nib file %@",nibFile);
|
||||
|
||||
[pool release];
|
||||
|
||||
[NSApp run];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void NSUpdateDynamicServices(void) {
|
||||
NSUnimplementedFunction();
|
||||
}
|
||||
|
||||
BOOL NSPerformService(NSString *itemName, NSPasteboard *pasteboard) {
|
||||
NSUnimplementedFunction();
|
||||
return NO;
|
||||
}
|
||||
|
39
AppKit/NSAttributedString.h
Executable file
39
AppKit/NSAttributedString.h
Executable file
@ -0,0 +1,39 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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 <Foundation/Foundation.h>
|
||||
#import <AppKit/AppKitExport.h>
|
||||
|
||||
@class NSFont,NSColor,NSParagraphStyle;
|
||||
|
||||
APPKIT_EXPORT NSString *NSFontAttributeName;
|
||||
APPKIT_EXPORT NSString *NSParagraphStyleAttributeName;
|
||||
APPKIT_EXPORT NSString *NSForegroundColorAttributeName;
|
||||
APPKIT_EXPORT NSString *NSBackgroundColorAttributeName;
|
||||
|
||||
APPKIT_EXPORT NSString *NSUnderlineStyleAttributeName;
|
||||
APPKIT_EXPORT NSString *NSAttachmentAttributeName;
|
||||
|
||||
enum {
|
||||
NSNoUnderlineStyle,
|
||||
NSSingleUnderlineStyle
|
||||
};
|
||||
|
||||
@interface NSAttributedString(NSAttributedString_AppKit)
|
||||
-initWithPath:(NSString *)path documentAttributes:(NSDictionary **)attributes;
|
||||
-(NSRange)doubleClickAtIndex:(unsigned)location;
|
||||
-(unsigned)nextWordFromIndex:(unsigned)location forward:(BOOL)forward;
|
||||
@end
|
||||
|
||||
// private
|
||||
NSFont *NSFontAttributeInDictionary(NSDictionary *dictionary);
|
||||
NSColor *NSForegroundColorAttributeInDictionary(NSDictionary *dictionary);
|
||||
NSColor *NSBackgroundColorAttributeInDictionary(NSDictionary *dictionary);
|
||||
NSParagraphStyle *NSParagraphStyleAttributeInDictionary(NSDictionary *dictionary);
|
||||
|
||||
#import <AppKit/NSMutableAttributedString.h>
|
175
AppKit/NSAttributedString.m
Executable file
175
AppKit/NSAttributedString.m
Executable file
@ -0,0 +1,175 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/NSAttributedString.h>
|
||||
#import <AppKit/NSFont.h>
|
||||
#import <AppKit/NSColor.h>
|
||||
#import <AppKit/NSParagraphStyle.h>
|
||||
#import <AppKit/NSRichTextReader.h>
|
||||
|
||||
NSString *NSFontAttributeName=@"NSFontAttributeName";
|
||||
NSString *NSParagraphStyleAttributeName=@"NSParagraphStyleAttributeName";
|
||||
NSString *NSForegroundColorAttributeName=@"NSForegroundColorAttributeName";
|
||||
NSString *NSBackgroundColorAttributeName=@"NSBackgroundColorAttributeName";
|
||||
|
||||
NSString *NSUnderlineStyleAttributeName=@"NSUnderlineStyleAttributeName";
|
||||
NSString *NSAttachmentAttributeName=@"NSAttachmentAttributeName";
|
||||
|
||||
@implementation NSAttributedString(NSAttributedString_AppKit)
|
||||
|
||||
-initWithPath:(NSString *)path documentAttributes:(NSDictionary **)attributes {
|
||||
NSAttributedString *string=[NSRichTextReader attributedStringWithContentsOfFile:path];
|
||||
if(string==nil){
|
||||
[self dealloc];
|
||||
return nil;
|
||||
}
|
||||
return [self initWithAttributedString:string];
|
||||
}
|
||||
|
||||
-(NSRange)doubleClickAtIndex:(unsigned)location {
|
||||
NSRange result=NSMakeRange(location,0);
|
||||
NSString *string=[self string];
|
||||
unsigned length=[string length];
|
||||
unichar character=[string characterAtIndex:location];
|
||||
NSCharacterSet *set;
|
||||
BOOL expand=NO;
|
||||
|
||||
set=[NSCharacterSet alphanumericCharacterSet];
|
||||
if([set characterIsMember:character])
|
||||
expand=YES;
|
||||
else {
|
||||
set=[NSCharacterSet whitespaceCharacterSet];
|
||||
if([set characterIsMember:character])
|
||||
expand=YES;
|
||||
}
|
||||
|
||||
if(expand){
|
||||
for(;result.location!=0;result.location--,result.length++) {
|
||||
if(![set characterIsMember:[string characterAtIndex:result.location-1]])
|
||||
break;
|
||||
}
|
||||
|
||||
for(;NSMaxRange(result)<length;result.length++){
|
||||
if(![set characterIsMember:[string characterAtIndex:NSMaxRange(result)]])
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if(location<length)
|
||||
result.length=1;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* as usual, the documentation says one thing and the system behaves differently, this is the way i think it should work... (dwy 5/11/2003) */
|
||||
-(unsigned)nextWordFromIndex:(unsigned)location forward:(BOOL)forward {
|
||||
NSCharacterSet *alpha = [NSCharacterSet alphanumericCharacterSet];
|
||||
NSString *string = [self string];
|
||||
int i = location, length = [self length];
|
||||
enum {
|
||||
STATE_INIT, // skipping all whitespace
|
||||
STATE_ALNUM, // body of word
|
||||
STATE_SPACE // word delimiter
|
||||
} state = STATE_ALNUM;
|
||||
|
||||
if (location == 0 && forward == NO) {
|
||||
// NSLog(@"sanity check: location == 0 && forward == NO");
|
||||
return location;
|
||||
}
|
||||
if (location >= [self length]) {
|
||||
// NSLog(@"sanity check: location >= [self length] && forward == YES");
|
||||
if (forward == YES)
|
||||
return [self length];
|
||||
else
|
||||
location = [self length]-1;
|
||||
}
|
||||
|
||||
if (forward) {
|
||||
if (![alpha characterIsMember:[string characterAtIndex:location]])
|
||||
state = STATE_INIT;
|
||||
|
||||
for (; i < length; ++i) {
|
||||
unichar ch = [string characterAtIndex:i];
|
||||
switch (state) {
|
||||
case STATE_INIT:
|
||||
if (![alpha characterIsMember:ch])
|
||||
state = STATE_ALNUM;
|
||||
break;
|
||||
case STATE_ALNUM:
|
||||
if ([alpha characterIsMember:ch])
|
||||
state = STATE_SPACE;
|
||||
break;
|
||||
case STATE_SPACE:
|
||||
if (![alpha characterIsMember:ch])
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
else {
|
||||
i--;
|
||||
if (![alpha characterIsMember:[string characterAtIndex:location]])
|
||||
state = STATE_INIT;
|
||||
|
||||
for (; i >= 0; i--) {
|
||||
unichar ch = [string characterAtIndex:i];
|
||||
switch (state) {
|
||||
case STATE_INIT:
|
||||
if (![alpha characterIsMember:ch])
|
||||
state = STATE_ALNUM;
|
||||
break;
|
||||
case STATE_ALNUM:
|
||||
if ([alpha characterIsMember:ch])
|
||||
state = STATE_SPACE;
|
||||
break;
|
||||
case STATE_SPACE:
|
||||
if (![alpha characterIsMember:ch])
|
||||
return i+1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return NSNotFound;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
NSFont *NSFontAttributeInDictionary(NSDictionary *dictionary) {
|
||||
NSFont *font=[dictionary objectForKey:NSFontAttributeName];
|
||||
|
||||
if(font==nil)
|
||||
font=[NSFont fontWithName:@"Arial" size:12.0];
|
||||
|
||||
return font;
|
||||
}
|
||||
|
||||
NSColor *NSForegroundColorAttributeInDictionary(NSDictionary *dictionary) {
|
||||
NSColor *color=[dictionary objectForKey:NSForegroundColorAttributeName];
|
||||
|
||||
if(color==nil)
|
||||
color=[NSColor blackColor];
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
NSColor *NSBackgroundColorAttributeInDictionary(NSDictionary *dictionary) {
|
||||
return [dictionary objectForKey:NSBackgroundColorAttributeName];
|
||||
}
|
||||
|
||||
NSParagraphStyle *NSParagraphStyleAttributeInDictionary(NSDictionary *dictionary) {
|
||||
NSParagraphStyle *style=[dictionary objectForKey:NSParagraphStyleAttributeName];
|
||||
|
||||
if(style==nil)
|
||||
style=[NSParagraphStyle defaultParagraphStyle];
|
||||
|
||||
return style;
|
||||
}
|
||||
|
25
AppKit/NSBitmapImageRep.h
Executable file
25
AppKit/NSBitmapImageRep.h
Executable file
@ -0,0 +1,25 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/NSImageRep.h>
|
||||
#import <AppKit/NSGraphics.h>
|
||||
|
||||
@interface NSBitmapImageRep : NSImageRep {
|
||||
unsigned _bitsPerPixel;
|
||||
unsigned _bytesPerRow;
|
||||
unsigned char *_bitmap;
|
||||
}
|
||||
|
||||
-initWithData:(NSData *)data;
|
||||
-initWithContentsOfFile:(NSString *)path;
|
||||
|
||||
+imageRepWithData:(NSData *)data;
|
||||
|
||||
-(void)compositeToPoint:(NSPoint)point operation:(NSCompositingOperation)operation fraction:(float)fraction;
|
||||
|
||||
@end
|
76
AppKit/NSBitmapImageRep.m
Executable file
76
AppKit/NSBitmapImageRep.m
Executable file
@ -0,0 +1,76 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/NSBitmapImageRep.h>
|
||||
#import <AppKit/NSGraphicsContextFunctions.h>
|
||||
#import <AppKit/NSView.h>
|
||||
#import <AppKit/CoreGraphics.h>
|
||||
#import <AppKit/NSTIFFReader.h>
|
||||
|
||||
@implementation NSBitmapImageRep
|
||||
|
||||
-initWithData:(NSData *)data {
|
||||
NSTIFFReader *reader=[[NSTIFFReader alloc] initWithData:data];
|
||||
int width=[reader pixelsWide];
|
||||
int height=[reader pixelsHigh];
|
||||
int npixels=width*height;
|
||||
|
||||
if(reader==nil){
|
||||
[self dealloc];
|
||||
return nil;
|
||||
}
|
||||
|
||||
npixels=width*height;
|
||||
_bitmap=NSZoneMalloc([self zone],(npixels*4*sizeof(unsigned char)));
|
||||
if(![reader getRGBAImageBytes:_bitmap width:width height:height]){
|
||||
[reader release];
|
||||
[self dealloc];
|
||||
return nil;
|
||||
}
|
||||
|
||||
_size.width=width;
|
||||
_size.height=height;
|
||||
|
||||
_bitsPerPixel=32;
|
||||
_bytesPerRow=_bitsPerPixel/sizeof(char)*width;
|
||||
|
||||
[reader release];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
-initWithContentsOfFile:(NSString *)path {
|
||||
NSData *data=[NSData dataWithContentsOfFile:path];
|
||||
|
||||
if(data==nil){
|
||||
[self dealloc];
|
||||
return nil;
|
||||
}
|
||||
|
||||
return [self initWithData:data];
|
||||
}
|
||||
|
||||
-(void)dealloc {
|
||||
if(_bitmap!=NULL){
|
||||
NSZoneFree([self zone],_bitmap);
|
||||
_bitmap=NULL;
|
||||
}
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
+imageRepWithData:(NSData *)data {
|
||||
return [[[self alloc] initWithData:data] autorelease];
|
||||
}
|
||||
|
||||
-(void)compositeToPoint:(NSPoint)point operation:(NSCompositingOperation)operation fraction:(float)fraction {
|
||||
CGContextSourceOverRGBAImage(NSCurrentGraphicsPort(),
|
||||
NSMakeRect(point.x,point.y,_size.width,_size.height),
|
||||
_size.width,_size.height,(void *)_bitmap,fraction);
|
||||
}
|
||||
|
||||
@end
|
32
AppKit/NSBox.h
Executable file
32
AppKit/NSBox.h
Executable file
@ -0,0 +1,32 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/NSView.h>
|
||||
|
||||
typedef enum {
|
||||
NSNoTitle,
|
||||
NSAboveTop,
|
||||
NSAtTop,
|
||||
NSBelowTop,
|
||||
NSAboveBottom,
|
||||
NSAtBottom,
|
||||
NSBelowBottom
|
||||
} NSTitlePosition;
|
||||
|
||||
@interface NSBox : NSView {
|
||||
id _titleCell;
|
||||
int _borderType;
|
||||
int _titlePosition;
|
||||
NSSize _contentViewMargins;
|
||||
}
|
||||
|
||||
-contentView;
|
||||
|
||||
-(void)setTitle:(NSString *)title;
|
||||
|
||||
@end
|
177
AppKit/NSBox.m
Executable file
177
AppKit/NSBox.m
Executable file
@ -0,0 +1,177 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/NSBox.h>
|
||||
#import <AppKit/NSApplication.h>
|
||||
#import <AppKit/NSGraphics.h>
|
||||
#import <AppKit/NSFont.h>
|
||||
#import <AppKit/NSAttributedString.h>
|
||||
#import <AppKit/NSColor.h>
|
||||
#import <AppKit/NSStringDrawing.h>
|
||||
#import <AppKit/NSParagraphStyle.h>
|
||||
#import <AppKit/NSStringDrawer.h>
|
||||
#import <AppKit/NSCell.h>
|
||||
#import <AppKit/NSNibKeyedUnarchiver.h>
|
||||
|
||||
@implementation NSBox
|
||||
|
||||
-(void)encodeWithCoder:(NSCoder *)coder {
|
||||
[super encodeWithCoder:coder];
|
||||
[coder encodeInt:_borderType forKey:@"NSBox borderType"];
|
||||
[coder encodeInt:_titlePosition forKey:@"NSBox titlePosition"];
|
||||
[coder encodeSize:_contentViewMargins forKey:@"NSBox contentViewMargins"];
|
||||
[coder encodeObject:_titleCell forKey:@"NSBox titleCell"];
|
||||
}
|
||||
|
||||
-initWithCoder:(NSCoder *)coder {
|
||||
[super initWithCoder:coder];
|
||||
|
||||
if([coder isKindOfClass:[NSNibKeyedUnarchiver class]]){
|
||||
NSNibKeyedUnarchiver *keyed=(NSNibKeyedUnarchiver *)coder;
|
||||
|
||||
_borderType=[keyed decodeIntForKey:@"NSBorderType"];
|
||||
_titlePosition=[keyed decodeIntForKey:@"NSTitlePosition"];
|
||||
_contentViewMargins=[keyed decodeSizeForKey:@"NSOffsets"];
|
||||
_titleCell=[[keyed decodeObjectForKey:@"NSTitleCell"] retain];
|
||||
[[_subviews lastObject] setAutoresizingMask: NSViewWidthSizable| NSViewHeightSizable];
|
||||
[[_subviews lastObject] setAutoresizesSubviews:YES];
|
||||
}
|
||||
else {
|
||||
_borderType=[coder decodeIntForKey:@"NSBox borderType"];
|
||||
_titlePosition=[coder decodeIntForKey:@"NSBox titlePosition"];
|
||||
_contentViewMargins=[coder decodeSizeForKey:@"NSBox contentViewMargins"];
|
||||
_titleCell=[[coder decodeObjectForKey:@"NSBox titleCell"] retain];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)dealloc {
|
||||
[_titleCell release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
-contentView {
|
||||
return [[self subviews] lastObject];
|
||||
}
|
||||
|
||||
-(void)setTitle:(NSString *)title {
|
||||
[_titleCell setStringValue:title];
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
-(NSAttributedString *)attributedTitle {
|
||||
NSMutableDictionary *attributes=[NSMutableDictionary dictionary];
|
||||
NSMutableParagraphStyle *paraStyle=[[[NSParagraphStyle defaultParagraphStyle] mutableCopy] autorelease];
|
||||
NSFont *font=[_titleCell font];
|
||||
|
||||
if(font!=nil)
|
||||
[attributes setObject:font forKey:NSFontAttributeName];
|
||||
|
||||
[paraStyle setLineBreakMode:NSLineBreakByClipping];
|
||||
[paraStyle setAlignment:NSLeftTextAlignment];
|
||||
[attributes setObject:paraStyle forKey:NSParagraphStyleAttributeName];
|
||||
|
||||
[attributes setObject:[NSColor controlTextColor]
|
||||
forKey: NSForegroundColorAttributeName];
|
||||
|
||||
[attributes setObject:[NSColor windowBackgroundColor]
|
||||
forKey:NSBackgroundColorAttributeName];
|
||||
|
||||
return [[[NSAttributedString alloc] initWithString:[_titleCell stringValue] attributes:attributes] autorelease];
|
||||
}
|
||||
|
||||
#define TEXTGAP 4
|
||||
|
||||
-(BOOL)isOpaque {
|
||||
return YES;
|
||||
}
|
||||
|
||||
-(void)drawRect:(NSRect)rect {
|
||||
NSAttributedString *title=[self attributedTitle];
|
||||
NSRect grooveRect=_bounds;
|
||||
NSSize titleSize=[title size];
|
||||
NSRect titleRect;
|
||||
BOOL drawTitle=YES;
|
||||
|
||||
titleRect.origin.x=10+TEXTGAP;
|
||||
titleSize.height=ceil(titleSize.height);
|
||||
titleSize.width=ceil(titleSize.width);
|
||||
titleRect.size=titleSize;
|
||||
|
||||
switch(_titlePosition){
|
||||
|
||||
case NSNoTitle:
|
||||
drawTitle=NO;
|
||||
break;
|
||||
|
||||
case NSAboveTop:
|
||||
titleRect.origin.y=_bounds.size.height-titleSize.height;
|
||||
grooveRect.size.height-=titleSize.height+TEXTGAP;
|
||||
break;
|
||||
|
||||
case NSAtTop:
|
||||
titleRect.origin.y=_bounds.size.height-titleSize.height;
|
||||
grooveRect.size.height-=floor(titleSize.height/2);
|
||||
break;
|
||||
|
||||
case NSBelowTop:
|
||||
titleRect.origin.y=_bounds.size.height-(titleSize.height+TEXTGAP);
|
||||
break;
|
||||
|
||||
case NSAboveBottom:
|
||||
titleRect.origin.y=TEXTGAP;
|
||||
break;
|
||||
|
||||
case NSAtBottom:
|
||||
grooveRect.origin.y+=floor(titleSize.height/2);
|
||||
grooveRect.size.height-=floor(titleSize.height/2);
|
||||
break;
|
||||
|
||||
case NSBelowBottom:
|
||||
titleRect.origin.y=0;
|
||||
grooveRect.origin.y+=titleSize.height+TEXTGAP;
|
||||
grooveRect.size.height-=titleSize.height+TEXTGAP;
|
||||
break;
|
||||
}
|
||||
|
||||
[[NSColor controlColor] set];
|
||||
NSRectFill(rect);
|
||||
|
||||
switch(_borderType){
|
||||
case NSNoBorder:
|
||||
break;
|
||||
|
||||
case NSLineBorder:
|
||||
[[NSColor blackColor] set];
|
||||
NSFrameRect(grooveRect);
|
||||
break;
|
||||
|
||||
case NSBezelBorder:
|
||||
NSDrawGrayBezel(grooveRect,rect);
|
||||
break;
|
||||
|
||||
case NSGrooveBorder:
|
||||
NSDrawGroove(grooveRect,rect);
|
||||
break;
|
||||
}
|
||||
|
||||
if(drawTitle){
|
||||
[[NSColor windowBackgroundColor] set];
|
||||
titleRect.origin.x-=TEXTGAP;
|
||||
titleRect.size.width+=TEXTGAP*2;
|
||||
NSRectFill(titleRect);
|
||||
titleRect.origin.x+=TEXTGAP;
|
||||
titleRect.size.width-=TEXTGAP*2;
|
||||
|
||||
[title _clipAndDrawInRect:titleRect];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@end
|
137
AppKit/NSBrowser.h
Executable file
137
AppKit/NSBrowser.h
Executable file
@ -0,0 +1,137 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/NSControl.h>
|
||||
|
||||
@class NSMatrix,NSScroller;
|
||||
|
||||
@interface NSBrowser : NSControl {
|
||||
id _target;
|
||||
SEL _action;
|
||||
SEL _doubleAction;
|
||||
|
||||
id _delegate;
|
||||
|
||||
NSMutableArray *_explicitTitles;
|
||||
NSMutableArray *_titles;
|
||||
NSMutableArray *_matrices;
|
||||
NSMutableArray *_scrollViews;
|
||||
NSScroller *_horizontalScroller;
|
||||
|
||||
Class _matrixClass;
|
||||
Class _cellClass;
|
||||
id _cellPrototype;
|
||||
int _numberOfVisibleColumns;
|
||||
int _minColumnWidth;
|
||||
int _firstVisibleColumn;
|
||||
int _maxVisibleColumns;
|
||||
int _selectedColumn;
|
||||
BOOL _reusesColumns;
|
||||
BOOL _hasHorizontalScroller;
|
||||
BOOL _separatesColumns;
|
||||
BOOL _isTitled;
|
||||
BOOL _allowsMultipleSelection;
|
||||
BOOL _allowsBranchSelection;
|
||||
BOOL _allowsEmptySelection;
|
||||
BOOL _takesTitleFromPreviousColumn;
|
||||
BOOL _acceptsArrowKeys;
|
||||
BOOL _sendsActionOnArrowKeys;
|
||||
}
|
||||
|
||||
-delegate;
|
||||
-(SEL)doubleAction;
|
||||
-(Class)matrixClass;
|
||||
-(int)maxVisibleColumns;
|
||||
-(BOOL)hasHorizontalScroller;
|
||||
-(BOOL)separatesColumns;
|
||||
-(BOOL)isTitled;
|
||||
-(BOOL)takesTitleFromPreviousColumn;
|
||||
-(BOOL)allowsMultipleSelection;
|
||||
-(BOOL)allowsBranchSelection;
|
||||
-(BOOL)allowsEmptySelection;
|
||||
-(BOOL)acceptsArrowKeys;
|
||||
-(BOOL)sendsActionOnArrowKeys;
|
||||
-(BOOL)reusesColumns;
|
||||
|
||||
-(int)lastColumn;
|
||||
-(int)lastVisibleColumn;
|
||||
-(int)firstVisibleColumn;
|
||||
|
||||
-(NSMatrix *)matrixInColumn:(int)column;
|
||||
-(int)columnOfMatrix:(NSMatrix *)matrix;
|
||||
-(NSString *)titleOfColumn:(int)column;
|
||||
|
||||
-(NSArray *)selectedCells;
|
||||
-selectedCell;
|
||||
-selectedCellInColumn:(int)column;
|
||||
-(int)selectedColumn;
|
||||
-(int)selectedRowInColumn:(int)column;
|
||||
|
||||
-(float)titleHeight;
|
||||
-(NSRect)titleFrameOfColumn:(int)column;
|
||||
-(NSRect)frameOfColumn:(int)column;
|
||||
-(NSRect)frameOfInsideOfColumn:(int)column;
|
||||
|
||||
-(void)setDelegate:delegate;
|
||||
-(void)setDoubleAction:(SEL)action;
|
||||
-(void)setMatrixClass:(Class)class;
|
||||
-(void)setCellClass:(Class)class;
|
||||
-(void)setMaxVisibleColumns:(int)count;
|
||||
-(void)setHasHorizontalScroller:(BOOL)flag;
|
||||
-(void)setSeparatesColumns:(BOOL)flag;
|
||||
-(void)setTitled:(BOOL)flag;
|
||||
-(void)setTakesTitleFromPreviousColumn:(BOOL)flag;
|
||||
-(void)setAllowsMultipleSelection:(BOOL)flag;
|
||||
-(void)setAllowsBranchSelection:(BOOL)flag;
|
||||
-(void)setAllowsEmptySelection:(BOOL)flag;
|
||||
-(void)setAcceptsArrowKeys:(BOOL)flag;
|
||||
-(void)setSendsActionOnArrowKeys:(BOOL)flag;
|
||||
-(void)setReusesColumns:(BOOL)flag;
|
||||
|
||||
-(void)setTitle:(NSString *)title ofColumn:(int)column;
|
||||
|
||||
-(void)selectRow:(int)row inColumn:(int)column;
|
||||
|
||||
-(void)doClick:sender;
|
||||
-(void)doDoubleClick:sender;
|
||||
|
||||
-(void)loadColumnZero;
|
||||
-(void)reloadColumn:(int)column;
|
||||
-(void)validateVisibleColumns;
|
||||
|
||||
-(void)scrollColumnsLeftBy:(int)delta;
|
||||
-(void)scrollColumnsRightBy:(int)delta;
|
||||
-(void)scrollColumnToVisible:(int)column;
|
||||
-(void)scrollViaScroller:(NSScroller *)sender;
|
||||
-(void)updateScroller;
|
||||
|
||||
-(void)drawTitleOfColumn:(int)column inRect:(NSRect)rect;
|
||||
|
||||
-(void)tile;
|
||||
|
||||
@end
|
||||
|
||||
@interface NSObject(NSBrowser_delegate)
|
||||
-(BOOL)browser:(NSBrowser *)browser isColumnValid:(int)column;
|
||||
|
||||
-(int)browser:(NSBrowser *)browser numberOfRowsInColumn:(int)column;
|
||||
-(void)browser:(NSBrowser *)browser createRowsForColumn:(int)column inMatrix:(NSMatrix *)matrix;
|
||||
|
||||
-(BOOL)browser:(NSBrowser *)browser selectRow:(int)row inColumn:(int)column;
|
||||
-(BOOL)browser:(NSBrowser *)browser selectCellWithString:(NSString *)title inColumn:(int)column;
|
||||
|
||||
-(NSString *)browser:(NSBrowser *)browser titleOfColumn:(int)column;
|
||||
|
||||
-(void)browserWillScroll:(NSBrowser *)browser;
|
||||
-(void)browserDidScroll:(NSBrowser *)browser;
|
||||
|
||||
-(void)browser:(NSBrowser *)browser willDisplayCell:cell atRow:(int)row column:(int)column;
|
||||
|
||||
@end
|
||||
|
||||
|
871
AppKit/NSBrowser.m
Executable file
871
AppKit/NSBrowser.m
Executable file
@ -0,0 +1,871 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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 - David Young <daver@geeks.org>, Christopher Lloyd <cjwl@objc.net>
|
||||
#import <AppKit/NSBrowser.h>
|
||||
#import <AppKit/NSBrowserCell.h>
|
||||
#import <AppKit/NSScrollView.h>
|
||||
#import <AppKit/NSClipView.h>
|
||||
#import <AppKit/NSScroller.h>
|
||||
#import <AppKit/NSColor.h>
|
||||
#import <AppKit/NSInterfaceGraphics.h>
|
||||
#import <AppKit/NSStringDrawing.h>
|
||||
#import <AppKit/NSMatrix.h>
|
||||
#import <AppKit/NSApplication.h>
|
||||
#import <AppKit/NSStringDrawer.h>
|
||||
#import <AppKit/NSWindow.h>
|
||||
#import <AppKit/NSNibKeyedUnarchiver.h>
|
||||
|
||||
@interface NSBrowser(Private)
|
||||
-(NSRect)frameOfScroller;
|
||||
@end
|
||||
|
||||
@implementation NSBrowser
|
||||
|
||||
+(Class)cellClass {
|
||||
return [NSBrowserCell class];
|
||||
}
|
||||
|
||||
-(void)encodeWithCoder:(NSCoder *)coder {
|
||||
NSUnimplementedMethod();
|
||||
}
|
||||
|
||||
-initWithCoder:(NSCoder *)coder {
|
||||
[super initWithCoder:coder];
|
||||
|
||||
if([coder isKindOfClass:[NSNibKeyedUnarchiver class]]){
|
||||
NSNibKeyedUnarchiver *keyed=(NSNibKeyedUnarchiver *)coder;
|
||||
unsigned flags=[keyed decodeIntForKey:@"NSBrFlags"];
|
||||
NSString *firstTitle=[keyed decodeObjectForKey:@"NSFirstColumnTitle"];
|
||||
|
||||
_explicitTitles=[NSMutableArray new];
|
||||
if(firstTitle!=nil)
|
||||
[_explicitTitles addObject:firstTitle];
|
||||
_titles=[NSMutableArray new];
|
||||
|
||||
_matrices=[NSMutableArray new];
|
||||
_scrollViews=[NSMutableArray new];
|
||||
|
||||
_matrixClass=[NSMatrix class];
|
||||
_cellClass=[[self class] cellClass];
|
||||
_cellPrototype=nil;
|
||||
|
||||
_numberOfVisibleColumns=[keyed decodeIntForKey:@"NSNumberOfVisibleColumns"];
|
||||
_selectedColumn=-1;
|
||||
|
||||
_allowsMultipleSelection=(flags&0x80000000)?YES:NO;
|
||||
_allowsEmptySelection=(flags&0x00020000)?NO:YES;
|
||||
_allowsBranchSelection=(flags&0x40000000)?YES:NO;
|
||||
_separatesColumns=(flags&0x04000000)?YES:NO;
|
||||
_isTitled=(flags&0x10000000)?YES:NO;
|
||||
_hasHorizontalScroller=(flags&0x00010000)?YES:NO;
|
||||
_horizontalScroller=nil; // not stored
|
||||
[self setHasHorizontalScroller:_hasHorizontalScroller];
|
||||
_acceptsArrowKeys=(flags&0x00100000)?YES:NO;
|
||||
_sendsActionOnArrowKeys=(flags&0x00040000)?YES:NO;
|
||||
|
||||
_takesTitleFromPreviousColumn=YES;
|
||||
|
||||
[self tile];
|
||||
}
|
||||
else {
|
||||
[NSException raise:NSInvalidArgumentException format:@"-[%@ %s] is not implemented for coder %@",isa,SELNAME(_cmd),coder];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-initWithFrame:(NSRect)frame {
|
||||
[super initWithFrame:frame];
|
||||
|
||||
_explicitTitles=[NSMutableArray new];
|
||||
[_explicitTitles addObject:@"Browser"];
|
||||
_titles=[NSMutableArray new];
|
||||
|
||||
_matrices=[NSMutableArray new];
|
||||
_scrollViews=[NSMutableArray new];
|
||||
|
||||
_horizontalScroller=nil;
|
||||
|
||||
_matrixClass=[NSMatrix class];
|
||||
_cellClass=[[self class] cellClass];
|
||||
_cellPrototype=nil;
|
||||
|
||||
_numberOfVisibleColumns=1;
|
||||
_allowsMultipleSelection=NO;
|
||||
_allowsEmptySelection=NO;
|
||||
_allowsBranchSelection=NO;
|
||||
_separatesColumns=NO;
|
||||
_isTitled=YES;
|
||||
_hasHorizontalScroller=NO;
|
||||
|
||||
_takesTitleFromPreviousColumn=YES;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)dealloc {
|
||||
[_explicitTitles release];
|
||||
[_titles release];
|
||||
[_matrices release];
|
||||
[_scrollViews release];
|
||||
[_horizontalScroller release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
-(Class)cellClass {
|
||||
return _cellClass;
|
||||
}
|
||||
|
||||
-target {
|
||||
return _target;
|
||||
}
|
||||
|
||||
-(SEL)action {
|
||||
return _action;
|
||||
}
|
||||
|
||||
-(void)setTarget:target {
|
||||
_target=target;
|
||||
}
|
||||
|
||||
-(void)setAction:(SEL)action {
|
||||
_action=action;
|
||||
}
|
||||
|
||||
-delegate {
|
||||
return _delegate;
|
||||
}
|
||||
|
||||
-(SEL)doubleAction {
|
||||
return _doubleAction;
|
||||
}
|
||||
|
||||
-(Class)matrixClass {
|
||||
return _matrixClass;
|
||||
}
|
||||
|
||||
-(int)maxVisibleColumns {
|
||||
return _maxVisibleColumns;
|
||||
}
|
||||
|
||||
-(BOOL)hasHorizontalScroller {
|
||||
return _hasHorizontalScroller;
|
||||
}
|
||||
|
||||
-(BOOL)separatesColumns {
|
||||
return _separatesColumns;
|
||||
}
|
||||
|
||||
-(BOOL)isTitled {
|
||||
return _isTitled;
|
||||
}
|
||||
|
||||
-(BOOL)takesTitleFromPreviousColumn {
|
||||
return _takesTitleFromPreviousColumn;
|
||||
}
|
||||
|
||||
-(BOOL)allowsMultipleSelection {
|
||||
return _allowsMultipleSelection;
|
||||
}
|
||||
|
||||
-(BOOL)allowsBranchSelection {
|
||||
return _allowsBranchSelection;
|
||||
}
|
||||
|
||||
-(BOOL)allowsEmptySelection {
|
||||
return _allowsEmptySelection;
|
||||
}
|
||||
|
||||
-(BOOL)acceptsArrowKeys {
|
||||
return _acceptsArrowKeys;
|
||||
}
|
||||
|
||||
-(BOOL)sendsActionOnArrowKeys {
|
||||
return _sendsActionOnArrowKeys;
|
||||
}
|
||||
|
||||
-(BOOL)reusesColumns {
|
||||
return _reusesColumns;
|
||||
}
|
||||
|
||||
-(int)lastColumn {
|
||||
return [_matrices count]-1;
|
||||
}
|
||||
|
||||
-(int)lastVisibleColumn {
|
||||
return [self firstVisibleColumn]+(_numberOfVisibleColumns-1);
|
||||
}
|
||||
|
||||
-(int)firstVisibleColumn {
|
||||
return _firstVisibleColumn;
|
||||
}
|
||||
|
||||
-(NSMatrix *)matrixInColumn:(int)column {
|
||||
if(column<[_matrices count])
|
||||
return [_matrices objectAtIndex:column];
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
-(int)columnOfMatrix:(NSMatrix *)matrix {
|
||||
return [_matrices indexOfObjectIdenticalTo:matrix];
|
||||
}
|
||||
|
||||
-(NSString *)titleOfColumn:(int)column {
|
||||
id result;
|
||||
|
||||
if(column>=[_titles count])
|
||||
result=@"";
|
||||
else {
|
||||
result=[_titles objectAtIndex:column];
|
||||
|
||||
if(result==[NSNull null]){
|
||||
if(column<[_explicitTitles count])
|
||||
result=[_explicitTitles objectAtIndex:column];
|
||||
else
|
||||
result=@"";
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
-(NSArray *)selectedCells {
|
||||
return [[self matrixInColumn:_selectedColumn] selectedCells];
|
||||
}
|
||||
|
||||
-selectedCell {
|
||||
return [self selectedCellInColumn:_selectedColumn];
|
||||
}
|
||||
|
||||
-selectedCellInColumn:(int)column {
|
||||
return [[self matrixInColumn:column] selectedCell];
|
||||
}
|
||||
|
||||
// This needs to be computed, manipulating individual cell state bypasses _selectedColumn
|
||||
// We should get rid of _selectedColumn eventually
|
||||
-(int)selectedColumn {
|
||||
int i,count=[_matrices count];
|
||||
|
||||
for(i=0;i<count;i++){
|
||||
NSMatrix *matrix=[_matrices objectAtIndex:i];
|
||||
|
||||
if([matrix selectedCell]==nil)
|
||||
break;
|
||||
}
|
||||
|
||||
return i-1;
|
||||
}
|
||||
|
||||
-(int)selectedRowInColumn:(int)column {
|
||||
return [[self matrixInColumn:column] selectedRow];
|
||||
}
|
||||
|
||||
-(float)seperatorWidth {
|
||||
return 2;
|
||||
}
|
||||
|
||||
-(float)titleHeight {
|
||||
return 20;
|
||||
}
|
||||
|
||||
-(NSRect)titleFrameOfColumn:(int)column {
|
||||
NSRect result;
|
||||
float columnGap=_separatesColumns?[self seperatorWidth]:0;
|
||||
|
||||
column-=[self firstVisibleColumn];
|
||||
|
||||
result.size.width=([self bounds].size.width-(_numberOfVisibleColumns-1)* columnGap)/_numberOfVisibleColumns;
|
||||
result.size.height=[self titleHeight];
|
||||
result.origin.x=column*(result.size.width+ columnGap);
|
||||
result.origin.y=[self bounds].size.height-result.size.height;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
-(NSRect)frameOfScrollerBorder {
|
||||
NSRect result=[self bounds];
|
||||
|
||||
result=NSInsetRect(result,2,2);
|
||||
result.size.height=[NSScroller scrollerWidth];
|
||||
result=NSInsetRect(result,-2,-2);
|
||||
return result;
|
||||
}
|
||||
|
||||
-(NSRect)frameOfScroller {
|
||||
NSRect result=[self frameOfScrollerBorder];
|
||||
|
||||
return NSInsetRect(result,2,2);
|
||||
}
|
||||
|
||||
-(NSRect)frameOfColumn:(int)column {
|
||||
NSRect result;
|
||||
NSRect titleFrame=[self titleFrameOfColumn:column];
|
||||
|
||||
result.origin.x=titleFrame.origin.x;
|
||||
result.size.width=titleFrame.size.width;
|
||||
result.origin.y=[self bounds].origin.y;
|
||||
result.size.height=[self bounds].size.height;
|
||||
|
||||
if([self isTitled])
|
||||
result.size.height-=titleFrame.size.height+[self seperatorWidth];
|
||||
|
||||
if([self hasHorizontalScroller]){
|
||||
result.origin.y+=[self frameOfScrollerBorder].size.height;
|
||||
result.size.height-=[self frameOfScrollerBorder].size.height;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
-(NSRect)frameOfInsideOfColumn:(int)column {
|
||||
NSScrollView *scrollView=[_scrollViews objectAtIndex:0];
|
||||
NSSize size=[scrollView contentSize];
|
||||
|
||||
return NSMakeRect(0,0,size.width,size.height);
|
||||
}
|
||||
|
||||
-(void)setDelegate:delegate {
|
||||
// check delegate validity
|
||||
if(![delegate respondsToSelector:@selector(browser:createRowsForColumn:inMatrix:)])
|
||||
if (![delegate respondsToSelector:@selector(browser:numberOfRowsInColumn:)] &&
|
||||
![delegate respondsToSelector:@selector(browser:willDisplayCell:atRow:column:)])
|
||||
[NSException raise:NSInternalInconsistencyException
|
||||
format:@"-[NSBrowser setDelegate:] doesn't implement delegate methods"];
|
||||
|
||||
_delegate=delegate;
|
||||
}
|
||||
|
||||
-(void)setDoubleAction:(SEL)action {
|
||||
_doubleAction=action;
|
||||
}
|
||||
|
||||
-(void)setMatrixClass:(Class)class {
|
||||
_matrixClass=class;
|
||||
}
|
||||
|
||||
-(void)setCellClass:(Class)class {
|
||||
_cellClass=class;
|
||||
}
|
||||
|
||||
-(void)setMaxVisibleColumns:(int)count {
|
||||
_maxVisibleColumns=count;
|
||||
_numberOfVisibleColumns=count;
|
||||
[self tile];
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
-(void)setHasHorizontalScroller:(BOOL)flag {
|
||||
_hasHorizontalScroller=flag;
|
||||
if(flag) {
|
||||
if(_horizontalScroller==nil){
|
||||
_horizontalScroller = [[NSScroller alloc] initWithFrame:[self frameOfScroller]];
|
||||
[_horizontalScroller setTarget:self];
|
||||
[_horizontalScroller setAction:@selector(scrollViaScroller:)];
|
||||
}
|
||||
}
|
||||
else {
|
||||
[_horizontalScroller release];
|
||||
_horizontalScroller = nil;
|
||||
}
|
||||
}
|
||||
|
||||
-(void)setSeparatesColumns:(BOOL)flag {
|
||||
_separatesColumns=flag;
|
||||
[self tile];
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
-(void)setTitled:(BOOL)flag {
|
||||
_isTitled=flag;
|
||||
[self tile];
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
-(void)setTakesTitleFromPreviousColumn:(BOOL)flag {
|
||||
_takesTitleFromPreviousColumn=flag;
|
||||
}
|
||||
|
||||
-(void)setAllowsMultipleSelection:(BOOL)flag {
|
||||
_allowsMultipleSelection=flag;
|
||||
}
|
||||
|
||||
-(void)setAllowsBranchSelection:(BOOL)flag {
|
||||
_allowsBranchSelection=flag;
|
||||
}
|
||||
|
||||
-(void)setAllowsEmptySelection:(BOOL)flag {
|
||||
_allowsEmptySelection=flag;
|
||||
}
|
||||
|
||||
-(void)setAcceptsArrowKeys:(BOOL)flag {
|
||||
_acceptsArrowKeys=flag;
|
||||
}
|
||||
|
||||
-(void)setSendsActionOnArrowKeys:(BOOL)flag {
|
||||
_sendsActionOnArrowKeys=flag;
|
||||
}
|
||||
|
||||
-(void)setReusesColumns:(BOOL)flag {
|
||||
_reusesColumns=flag;
|
||||
}
|
||||
|
||||
-(void)setTitle:(NSString *)title ofColumn:(int)column {
|
||||
while([_explicitTitles count]<=column)
|
||||
[_explicitTitles addObject:@""];
|
||||
|
||||
[_explicitTitles replaceObjectAtIndex:column withObject:title];
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
-(void)_unloadAfterColumn:(int)column {
|
||||
while([_matrices count]>column+1){
|
||||
NSMatrix *matrix=[_matrices lastObject];
|
||||
|
||||
[matrix removeFromSuperview];
|
||||
[_matrices removeLastObject];
|
||||
[_titles removeLastObject];
|
||||
}
|
||||
|
||||
[self setNeedsDisplay:YES];
|
||||
[self updateScroller];
|
||||
}
|
||||
|
||||
-(void)_reloadSelectionInColumn:(int)column {
|
||||
NSMatrix *matrix=[self matrixInColumn:column];
|
||||
NSArray *selectedCells=[matrix selectedCells];
|
||||
|
||||
[_cell autorelease];
|
||||
_cell=[[matrix selectedCell] retain];
|
||||
_selectedColumn=column;
|
||||
|
||||
// if multiple cells are selected, the display of that branch is invalid and must be unloaded.
|
||||
if([selectedCells count]>1)
|
||||
[self _unloadAfterColumn:_selectedColumn];
|
||||
else if(_cell!=nil && ![_cell isLeaf]){
|
||||
[self reloadColumn:_selectedColumn+1];
|
||||
[self _unloadAfterColumn:_selectedColumn+1];
|
||||
|
||||
if(_selectedColumn==[self lastVisibleColumn])
|
||||
[self scrollColumnsRightBy:1];
|
||||
}
|
||||
else if(_cell!=nil) // valid cell, no following branch
|
||||
[self _unloadAfterColumn:_selectedColumn];
|
||||
|
||||
[self scrollColumnToVisible:_selectedColumn];
|
||||
}
|
||||
|
||||
-(void)selectRow:(int)row inColumn:(int)column {
|
||||
_selectedColumn = column;
|
||||
|
||||
if(column<[_matrices count]){
|
||||
NSMatrix *matrix=[self matrixInColumn:column];
|
||||
|
||||
#if 0
|
||||
if([self allowsMultipleSelection]){
|
||||
NSBrowserCell *theLuckyCell = [matrix cellAtRow:row column:0];
|
||||
|
||||
// branch selection logic. "whether the user can
|
||||
// select branch items when multiple selection is enabled"
|
||||
if ([self selectedCells] > 0 && theLuckyCell != [self selectedCell])
|
||||
if (![theLuckyCell isLeaf])
|
||||
if (![self allowsBranchSelection])
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
[matrix selectCellAtRow:row column:0];
|
||||
[matrix scrollRectToVisible:[matrix cellFrameAtRow:row column:0]];
|
||||
|
||||
[self _reloadSelectionInColumn:column];
|
||||
}
|
||||
}
|
||||
|
||||
-(void)doClick:sender {
|
||||
[self _reloadSelectionInColumn:[self columnOfMatrix:sender]];
|
||||
|
||||
if ([[[self window] currentEvent] type] != NSKeyDown || _sendsActionOnArrowKeys == YES)
|
||||
[self sendAction:[self action] to:[self target]];
|
||||
}
|
||||
|
||||
-(void)doDoubleClick:sender {
|
||||
[self sendAction:[self doubleAction] to:[self target]];
|
||||
}
|
||||
|
||||
-(void)unloadLastColumn {
|
||||
NSMatrix *matrix=[_matrices lastObject];
|
||||
|
||||
[[matrix superview] setDocumentView:nil];
|
||||
[_matrices removeLastObject];
|
||||
[_titles removeLastObject];
|
||||
[self setNeedsDisplay:YES];
|
||||
[self updateScroller];
|
||||
}
|
||||
|
||||
-(void)loadColumnZero {
|
||||
while([_matrices count]>1)
|
||||
[self unloadLastColumn];
|
||||
|
||||
[self reloadColumn:0];
|
||||
}
|
||||
|
||||
-(NSMatrix *)createMatrixInColumn:(int)column {
|
||||
while([_matrices count]<=column){
|
||||
NSRect frame=[self frameOfInsideOfColumn:column];
|
||||
NSMatrix *matrix=[[[_matrixClass alloc] initWithFrame:frame] autorelease];
|
||||
|
||||
[matrix setTarget:self];
|
||||
[matrix setAction:@selector(doClick:)];
|
||||
[matrix setDoubleAction:@selector(doDoubleClick:)];
|
||||
|
||||
[matrix setCellClass:[self cellClass]];
|
||||
[matrix setCellSize:NSMakeSize(frame.size.width,16)];
|
||||
[matrix setAutoresizingMask:NSViewWidthSizable];
|
||||
[matrix setAutosizesCells:YES];
|
||||
[matrix setAllowsEmptySelection:[self allowsEmptySelection]];
|
||||
|
||||
if([self allowsMultipleSelection])
|
||||
[matrix setMode:NSListModeMatrix];
|
||||
else
|
||||
[matrix setMode:NSRadioModeMatrix];
|
||||
|
||||
#if 0
|
||||
if(column>=[self firstVisibleColumn] && column<=[self lastVisibleColumn]){
|
||||
NSScrollView *scrollView=[_scrollViews objectAtIndex:column-[self firstVisibleColumn]];
|
||||
|
||||
[scrollView setDocumentView:matrix];
|
||||
}
|
||||
#endif
|
||||
|
||||
[_titles addObject:[NSNull null]];
|
||||
[_matrices addObject:matrix];
|
||||
}
|
||||
|
||||
if(column>=[self firstVisibleColumn] && column<=[self lastVisibleColumn]){
|
||||
NSScrollView *scrollView=[_scrollViews objectAtIndex:column-[self firstVisibleColumn]];
|
||||
|
||||
[scrollView setDocumentView:[_matrices objectAtIndex:column]];
|
||||
[scrollView setLineScroll:[[_matrices objectAtIndex:column] cellSize].height];
|
||||
[scrollView setPageScroll:[[scrollView contentView] frame].size.height];
|
||||
}
|
||||
|
||||
[self updateScroller];
|
||||
return [_matrices objectAtIndex:column];
|
||||
}
|
||||
|
||||
-(NSMatrix *)_reloadColumn:(int)column preserveSelection:(BOOL)preserveSelection {
|
||||
NSMatrix *matrix=[self createMatrixInColumn:column];
|
||||
int selectedRow=[matrix selectedRow],selectedColumn=[matrix selectedColumn];
|
||||
id title=[NSNull null];
|
||||
|
||||
[matrix renewRows:0 columns:1];
|
||||
|
||||
if([_delegate respondsToSelector:@selector(browser:createRowsForColumn:inMatrix:)])
|
||||
[_delegate browser:self createRowsForColumn:column inMatrix:matrix];
|
||||
else {
|
||||
int nrows=[_delegate browser:self numberOfRowsInColumn:column];
|
||||
int i;
|
||||
|
||||
[matrix renewRows:nrows columns:1];
|
||||
|
||||
for(i=0;i<nrows;i++){
|
||||
[_delegate browser:self willDisplayCell:[matrix cellAtRow:i column:0] atRow:i column:column];
|
||||
}
|
||||
}
|
||||
|
||||
[matrix sizeToFit];
|
||||
|
||||
if(preserveSelection)
|
||||
[matrix selectCellAtRow:selectedRow column:selectedColumn];
|
||||
else
|
||||
[self _unloadAfterColumn:column];
|
||||
|
||||
[matrix setNeedsDisplay:YES];
|
||||
|
||||
if([_delegate respondsToSelector:@selector(browser:titleOfColumn:)])
|
||||
title=[_delegate browser:self titleOfColumn:column];
|
||||
else if(_takesTitleFromPreviousColumn){
|
||||
if(column>0){
|
||||
title=[[[self matrixInColumn:column-1] selectedCell] stringValue];
|
||||
}
|
||||
}
|
||||
|
||||
[_titles replaceObjectAtIndex:column withObject:title];
|
||||
|
||||
return matrix;
|
||||
}
|
||||
|
||||
-(void)reloadColumn:(int)column {
|
||||
[self _reloadColumn:column preserveSelection:NO];
|
||||
}
|
||||
|
||||
-(void)validateVisibleColumns {
|
||||
int i;
|
||||
|
||||
if([_delegate respondsToSelector:@selector(browser:isColumnValid:)]){
|
||||
for(i=[self firstVisibleColumn];i<=[self lastVisibleColumn];i++){
|
||||
NSMatrix *matrix;
|
||||
|
||||
if(![_delegate browser:self isColumnValid:i])
|
||||
[self _reloadColumn:i preserveSelection:YES];
|
||||
|
||||
matrix=[self matrixInColumn:i];
|
||||
if([matrix selectedRow]<0){
|
||||
[self _unloadAfterColumn:i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-(void)scrollColumnsLeftBy:(int)offset {
|
||||
int i, scrollViewIndex = 0;
|
||||
|
||||
if (_firstVisibleColumn - offset < 0)
|
||||
offset = _firstVisibleColumn;
|
||||
|
||||
if (offset < 1)
|
||||
return;
|
||||
|
||||
_firstVisibleColumn -= offset;
|
||||
|
||||
for (i = _firstVisibleColumn; i <= [self lastVisibleColumn] && i<[_matrices count]; i++){
|
||||
NSView * matrix =(i<[_matrices count])?[_matrices objectAtIndex:i]:nil;
|
||||
|
||||
[[_scrollViews objectAtIndex:scrollViewIndex++] setDocumentView:matrix];
|
||||
}
|
||||
|
||||
[self updateScroller];
|
||||
}
|
||||
|
||||
-(void)scrollColumnsRightBy:(int)offset {
|
||||
int i, scrollViewIndex = 0;
|
||||
|
||||
if ([self lastVisibleColumn] + offset >= [_matrices count])
|
||||
offset = [_matrices count] - [self lastVisibleColumn] - 1;
|
||||
|
||||
if (offset < 1)
|
||||
return;
|
||||
|
||||
_firstVisibleColumn += offset;
|
||||
|
||||
// NB here we swap in reverse, since a view doesn't display properly if it is
|
||||
// the docView of two scrollViews at once. bug or feature?
|
||||
scrollViewIndex = [_scrollViews count]-1;
|
||||
for (i = [self lastVisibleColumn]; i >= _firstVisibleColumn; --i){
|
||||
[[_scrollViews objectAtIndex:scrollViewIndex--] setDocumentView:[_matrices objectAtIndex:i]];
|
||||
}
|
||||
|
||||
[self updateScroller];
|
||||
}
|
||||
|
||||
-(void)scrollColumnToVisible:(int)column {
|
||||
if (column >= [self firstVisibleColumn] && column <= [self lastVisibleColumn])
|
||||
return; // already visible
|
||||
|
||||
if (column < _firstVisibleColumn)
|
||||
[self scrollColumnsLeftBy:_firstVisibleColumn-column];
|
||||
else
|
||||
[self scrollColumnsRightBy:column-[self lastVisibleColumn]];
|
||||
}
|
||||
|
||||
-(void)scrollViaScroller:(NSScroller *)sender {
|
||||
switch ([sender hitPart]) {
|
||||
case NSScrollerDecrementLine:
|
||||
case NSScrollerDecrementPage:
|
||||
[self scrollColumnsLeftBy:1];
|
||||
break;
|
||||
|
||||
case NSScrollerIncrementLine:
|
||||
case NSScrollerIncrementPage:
|
||||
[self scrollColumnsRightBy:1];
|
||||
break;
|
||||
|
||||
case NSScrollerKnob:
|
||||
case NSScrollerKnobSlot:
|
||||
[self scrollColumnToVisible:[sender floatValue]*[_matrices count]];
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
-(void)updateScroller {
|
||||
if (_firstVisibleColumn+_numberOfVisibleColumns > [_matrices count])
|
||||
[self scrollColumnsLeftBy:1];
|
||||
|
||||
if ([_matrices count] == 0 || [_matrices count] <= _numberOfVisibleColumns) {
|
||||
[_horizontalScroller setFloatValue:0.0 knobProportion:1.0];
|
||||
[_horizontalScroller setEnabled:NO];
|
||||
}
|
||||
else {
|
||||
float val = (float)_firstVisibleColumn/(float)([_matrices count]-_numberOfVisibleColumns);
|
||||
float knobP = (float)_numberOfVisibleColumns/(float)[_matrices count];
|
||||
|
||||
[_horizontalScroller setFloatValue:val knobProportion:knobP];
|
||||
[_horizontalScroller setEnabled:YES];
|
||||
}
|
||||
|
||||
[_horizontalScroller setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
-(void)drawTitleOfColumn:(int)column inRect:(NSRect)rect {
|
||||
NSString *title=[self titleOfColumn:column];
|
||||
NSSize titleSize=[title sizeWithAttributes:nil];
|
||||
NSRect titleFrame=NSInsetRect(rect,2,0);
|
||||
|
||||
titleFrame.size.height=titleSize.height;
|
||||
titleFrame.origin.y+=floor((rect.size.height-titleSize.height)/2);
|
||||
|
||||
[[self titleOfColumn:column] _clipAndDrawInRect:titleFrame withAttributes:nil];
|
||||
}
|
||||
|
||||
-(NSScrollView *)createScrollViewAtIndex:(int)index {
|
||||
while([_scrollViews count]<=index){
|
||||
int column=_firstVisibleColumn+[_scrollViews count];
|
||||
NSRect frame=[self frameOfColumn:column];
|
||||
NSScrollView *view=[[[NSScrollView alloc] initWithFrame:frame] autorelease];
|
||||
|
||||
[view setBorderType:NSBezelBorder];
|
||||
[view setHasVerticalScroller:YES];
|
||||
[view setHasHorizontalScroller:NO];
|
||||
[view setAutoresizesSubviews:YES];
|
||||
|
||||
[_scrollViews addObject:view];
|
||||
[self addSubview:view];
|
||||
}
|
||||
|
||||
return [_scrollViews objectAtIndex:index];
|
||||
}
|
||||
|
||||
-(void)tile {
|
||||
int i;
|
||||
|
||||
for(i=0;i<_numberOfVisibleColumns;i++){
|
||||
int column=_firstVisibleColumn+i;
|
||||
NSRect frame=[self frameOfColumn:column];
|
||||
NSView *scrollView=[self createScrollViewAtIndex:i];
|
||||
|
||||
[scrollView setFrame:frame];
|
||||
}
|
||||
|
||||
while([_scrollViews count]>_firstVisibleColumn+i){
|
||||
[[_scrollViews lastObject] removeFromSuperview];
|
||||
[_scrollViews removeLastObject];
|
||||
}
|
||||
|
||||
[_horizontalScroller setFrame:[self frameOfScroller]];
|
||||
}
|
||||
|
||||
-(void)setEnabled:(BOOL)enabled {
|
||||
int count=[_matrices count];
|
||||
|
||||
while(--count>=0){
|
||||
[[_matrices objectAtIndex:count] setEnabled:enabled];
|
||||
}
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
-(BOOL)isOpaque {
|
||||
return YES;
|
||||
}
|
||||
|
||||
-(void)drawRect:(NSRect)rect {
|
||||
int i;
|
||||
|
||||
[[NSColor controlColor] set];
|
||||
NSRectFill(rect);
|
||||
|
||||
if([self isTitled]){
|
||||
for(i=[self firstVisibleColumn];i<=[self lastVisibleColumn];i++){
|
||||
NSRect titleRect=[self titleFrameOfColumn:i];
|
||||
|
||||
NSInterfaceDrawBrowserHeader(titleRect,titleRect);
|
||||
|
||||
titleRect=NSInsetRect(titleRect,2,2);
|
||||
|
||||
[self drawTitleOfColumn:i inRect:titleRect];
|
||||
}
|
||||
}
|
||||
|
||||
if([self hasHorizontalScroller])
|
||||
NSDrawGrayBezel([self frameOfScrollerBorder],rect);
|
||||
|
||||
}
|
||||
|
||||
-(void)resizeSubviewsWithOldSize:(NSSize)oldSize {
|
||||
[self tile];
|
||||
}
|
||||
|
||||
-(void)mouseDown:(NSEvent *)event {
|
||||
// do nothing, but override NSControl's implementation
|
||||
}
|
||||
|
||||
|
||||
-(void)keyDown:(NSEvent *)event {
|
||||
if (_acceptsArrowKeys == YES)
|
||||
[self interpretKeyEvents:[NSArray arrayWithObject:event]];
|
||||
}
|
||||
|
||||
// up arrow
|
||||
-(void)moveBackward:sender {
|
||||
int selectedRow = [self selectedRowInColumn:_selectedColumn];
|
||||
|
||||
if (selectedRow > 0) {
|
||||
if (!([[[self window] currentEvent] modifierFlags] & NSShiftKeyMask))
|
||||
[[self matrixInColumn:_selectedColumn] deselectAllCells];
|
||||
|
||||
[self selectRow:selectedRow - 1 inColumn:_selectedColumn];
|
||||
[self doClick:[self matrixInColumn:_selectedColumn]];
|
||||
}
|
||||
}
|
||||
|
||||
-(void)moveForward:sender {
|
||||
int selectedRow = [self selectedRowInColumn:_selectedColumn];
|
||||
if (selectedRow < [[self matrixInColumn:_selectedColumn] numberOfRows] - 1) {
|
||||
if (!([[[self window] currentEvent] modifierFlags] & NSShiftKeyMask))
|
||||
[[self matrixInColumn:_selectedColumn] deselectAllCells];
|
||||
|
||||
[self selectRow:selectedRow + 1 inColumn:_selectedColumn];
|
||||
[self doClick:[self matrixInColumn:_selectedColumn]];
|
||||
}
|
||||
}
|
||||
|
||||
-(void)moveUp:sender {
|
||||
[self moveBackward:sender];
|
||||
}
|
||||
|
||||
-(void)moveDown:sender {
|
||||
[self moveForward:sender];
|
||||
}
|
||||
|
||||
-(void)moveLeft:sender {
|
||||
if (_selectedColumn > 0) {
|
||||
if (![[self selectedCell] isLeaf])
|
||||
[self _unloadAfterColumn:_selectedColumn];
|
||||
if ([self allowsEmptySelection] == YES)
|
||||
[[self matrixInColumn:_selectedColumn] deselectAllCells];
|
||||
|
||||
// [self selectRow:0 inColumn:_selectedColumn - 1];
|
||||
_selectedColumn--;
|
||||
//NSLog(@"selectedColumn %d count %d", _selectedColumn, [_matrices count]);
|
||||
[self doClick:[self matrixInColumn:_selectedColumn]];
|
||||
}
|
||||
}
|
||||
|
||||
-(void)moveRight:sender {
|
||||
if (![[self selectedCell] isLeaf]) {
|
||||
[self selectRow:0 inColumn:_selectedColumn + 1]; // nb this changes _selectedColumn
|
||||
[self doClick:[self matrixInColumn:_selectedColumn]];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
28
AppKit/NSBrowserCell.h
Executable file
28
AppKit/NSBrowserCell.h
Executable file
@ -0,0 +1,28 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/NSCell.h>
|
||||
|
||||
@interface NSBrowserCell : NSCell {
|
||||
BOOL _isLeaf;
|
||||
BOOL _isLoaded;
|
||||
}
|
||||
|
||||
+(NSImage *)branchImage;
|
||||
+(NSImage *)highlightedBranchImage;
|
||||
|
||||
-(BOOL)isLeaf;
|
||||
-(BOOL)isLoaded;
|
||||
|
||||
-(void)setLeaf:(BOOL)flag;
|
||||
-(void)setLoaded:(BOOL)flag;
|
||||
|
||||
-(void)set;
|
||||
-(void)reset;
|
||||
|
||||
@end
|
121
AppKit/NSBrowserCell.m
Executable file
121
AppKit/NSBrowserCell.m
Executable file
@ -0,0 +1,121 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/NSBrowserCell.h>
|
||||
#import <AppKit/NSStringDrawing.h>
|
||||
#import <AppKit/NSImage.h>
|
||||
#import <AppKit/NSColor.h>
|
||||
#import <AppKit/NSMatrix.h>
|
||||
#import <AppKit/NSAttributedString.h>
|
||||
#import <AppKit/NSStringDrawer.h>
|
||||
|
||||
@implementation NSBrowserCell
|
||||
|
||||
+(NSImage *)branchImage {
|
||||
return [NSImage imageNamed:@"NSBrowserCellArrow"];
|
||||
}
|
||||
|
||||
+(NSImage *)highlightedBranchImage {
|
||||
return [NSImage imageNamed:@"NSHighlightedBrowserCellArrow"];
|
||||
}
|
||||
|
||||
-(BOOL)isLeaf {
|
||||
return _isLeaf;
|
||||
}
|
||||
|
||||
-(BOOL)isLoaded {
|
||||
return _isLoaded;
|
||||
}
|
||||
|
||||
-(void)setLeaf:(BOOL)flag {
|
||||
_isLeaf=flag;
|
||||
}
|
||||
|
||||
-(void)setLoaded:(BOOL)flag {
|
||||
_isLoaded=flag;
|
||||
}
|
||||
|
||||
-(void)setState:(int)value {
|
||||
_state=value;
|
||||
_isHighlighted=(_state==NSOnState)?YES:NO;
|
||||
}
|
||||
|
||||
-(void)set {
|
||||
[self setState:NSOnState];
|
||||
_isHighlighted=YES;
|
||||
}
|
||||
|
||||
-(void)reset {
|
||||
[self setState:NSOffState];
|
||||
_isHighlighted=NO;
|
||||
}
|
||||
|
||||
-(NSImage *)branchImage {
|
||||
if([self isLeaf])
|
||||
return nil;
|
||||
else if([self isHighlighted] || [self state])
|
||||
return [NSBrowserCell highlightedBranchImage];
|
||||
else
|
||||
return [NSBrowserCell branchImage];
|
||||
}
|
||||
|
||||
-(BOOL)wraps {
|
||||
return NO;
|
||||
}
|
||||
|
||||
-(void)drawInteriorWithFrame:(NSRect)frame inView:(NSView *)control {
|
||||
NSAttributedString *title=[self attributedStringValue];
|
||||
NSImage *branchImage=[self branchImage];
|
||||
NSSize branchImageSize=(branchImage==nil)?NSMakeSize(0,0):[branchImage size];
|
||||
NSPoint branchImageOrigin=frame.origin;
|
||||
NSImage *image=[self image];
|
||||
NSSize imageSize=(image==nil)?NSMakeSize(0,0):[image size];
|
||||
NSPoint imageOrigin=frame.origin;
|
||||
NSSize titleSize=[title size];
|
||||
NSRect titleRect=frame;
|
||||
BOOL drawBranchImage=YES,drawTitle=YES,drawImage=YES;
|
||||
|
||||
branchImageOrigin.x=frame.origin.x+(frame.size.width-branchImageSize.width);
|
||||
branchImageOrigin.y+=floor((frame.size.height-branchImageSize.height)/2);
|
||||
|
||||
imageOrigin.x=frame.origin.x;
|
||||
imageOrigin.y+=floor((frame.size.height-imageSize.height)/2);
|
||||
|
||||
titleRect.origin.x+=imageSize.width+2;
|
||||
titleRect.size.width-=imageSize.width+2;
|
||||
titleRect.origin.y+=floor((titleRect.size.height-titleSize.height)/2);
|
||||
titleRect.size.height=titleSize.height;
|
||||
|
||||
titleRect.size.width-=(branchImageSize.width+2);
|
||||
|
||||
if([self isHighlighted] || [self state]){
|
||||
if([title attribute:NSForegroundColorAttributeName atIndex:0 effectiveRange:NULL]==nil){
|
||||
NSMutableAttributedString *change=[[title mutableCopy] autorelease];
|
||||
|
||||
[change addAttribute:NSForegroundColorAttributeName value:[NSColor whiteColor] range:NSMakeRange(0,[title length])];
|
||||
title=change;
|
||||
}
|
||||
[[NSColor selectedControlColor] set];
|
||||
}
|
||||
else
|
||||
[[NSColor controlBackgroundColor] set];
|
||||
|
||||
NSRectFill(frame);
|
||||
|
||||
if(drawTitle)
|
||||
[title _clipAndDrawInRect:titleRect];
|
||||
|
||||
if(drawBranchImage)
|
||||
[branchImage compositeToPoint:branchImageOrigin operation:NSCompositeSourceOver];
|
||||
|
||||
if(drawImage)
|
||||
[image compositeToPoint:imageOrigin operation:NSCompositeSourceOver];
|
||||
}
|
||||
|
||||
@end
|
BIN
AppKit/NSBrowserCellArrow.tiff
Executable file
BIN
AppKit/NSBrowserCellArrow.tiff
Executable file
Binary file not shown.
30
AppKit/NSButton.h
Executable file
30
AppKit/NSButton.h
Executable file
@ -0,0 +1,30 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/NSControl.h>
|
||||
#import <AppKit/NSButtonCell.h>
|
||||
|
||||
@interface NSButton : NSControl
|
||||
|
||||
-(BOOL)isTransparent;
|
||||
-(NSString *)keyEquivalent;
|
||||
-(NSImage *)image;
|
||||
-(NSCellImagePosition)imagePosition;
|
||||
-(NSString *)title;
|
||||
-(int)state;
|
||||
|
||||
-(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)performClick:sender;
|
||||
|
||||
@end
|
131
AppKit/NSButton.m
Executable file
131
AppKit/NSButton.m
Executable file
@ -0,0 +1,131 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/NSButton.h>
|
||||
#import <AppKit/NSButtonCell.h>
|
||||
#import <AppKit/NSApplication.h>
|
||||
#import <AppKit/NSWindow.h>
|
||||
|
||||
@implementation NSButton
|
||||
|
||||
+(Class)cellClass {
|
||||
return [NSButtonCell class];
|
||||
}
|
||||
|
||||
-(BOOL)resignFirstResponder {
|
||||
[self setNeedsDisplay:YES];
|
||||
return [super resignFirstResponder];
|
||||
}
|
||||
|
||||
-(BOOL)isOpaque {
|
||||
return ![_cell isTransparent] && [_cell isBordered];
|
||||
}
|
||||
|
||||
-(BOOL)isTransparent {
|
||||
return [_cell isTransparent];
|
||||
}
|
||||
|
||||
-(NSString *)keyEquivalent {
|
||||
return [_cell keyEquivalent];
|
||||
}
|
||||
|
||||
-(NSImage *)image {
|
||||
return [_cell image];
|
||||
}
|
||||
|
||||
-(NSCellImagePosition)imagePosition {
|
||||
return [_cell imagePosition];
|
||||
}
|
||||
|
||||
-(NSString *)title {
|
||||
return [_cell title];
|
||||
}
|
||||
|
||||
-(int)state {
|
||||
return [_cell state];
|
||||
}
|
||||
|
||||
|
||||
-(void)setTransparent:(BOOL)flag {
|
||||
[_cell setTransparent:flag];
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
-(void)setKeyEquivalent:(NSString *)keyEquivalent {
|
||||
[_cell setKeyEquivalent:keyEquivalent];
|
||||
}
|
||||
|
||||
-(void)setImage:(NSImage *)image {
|
||||
[_cell setImage:image];
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
-(void)setImagePosition:(NSCellImagePosition)position {
|
||||
[_cell setImagePosition:position];
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
-(void)setTitle:(NSString *)title {
|
||||
[_cell setTitle:title];
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
-(void)setState:(int)value {
|
||||
[_cell setState:value];
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
-(unsigned)keyEquivalentModifierMask {
|
||||
return [_cell keyEquivalentModifierMask];
|
||||
}
|
||||
|
||||
-(void)setKeyEquivalentModifierMask:(unsigned)mask {
|
||||
[_cell setKeyEquivalentModifierMask:mask];
|
||||
}
|
||||
|
||||
-(BOOL)performKeyEquivalent:(NSEvent *)event {
|
||||
NSString *characters=[event charactersIgnoringModifiers];
|
||||
unsigned modifiers=[event modifierFlags];
|
||||
|
||||
if(![self isEnabled])
|
||||
return NO;
|
||||
|
||||
if((modifiers&(NSCommandKeyMask|NSAlternateKeyMask))==[self keyEquivalentModifierMask]){
|
||||
NSString *key=[self keyEquivalent];
|
||||
|
||||
if([key isEqualToString:characters]){
|
||||
[self performClick:nil];
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
-(void)performClick:sender {
|
||||
[self lockFocus];
|
||||
[_cell highlight:YES withFrame:[self bounds] inView:self];
|
||||
[self unlockFocus];
|
||||
[[self window] flushWindow];
|
||||
|
||||
[[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];
|
||||
}
|
||||
|
||||
-(void)keyDown:(NSEvent *)event {
|
||||
[self interpretKeyEvents:[NSArray arrayWithObject:event]];
|
||||
}
|
||||
|
||||
@end
|
76
AppKit/NSButtonCell.h
Executable file
76
AppKit/NSButtonCell.h
Executable file
@ -0,0 +1,76 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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>
|
||||
|
||||
enum {
|
||||
NSNoCellMask=0x00,
|
||||
NSContentsCellMask=0x01,
|
||||
NSPushInCellMask=0x02,
|
||||
NSChangeGrayCellMask=0x04,
|
||||
NSChangeBackgroundCellMask=0x08,
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
NSRoundedBezelStyle=1,
|
||||
NSRegularSquareBezelStyle,
|
||||
NSThickSquareBezelStyle,
|
||||
NSThickerSquareBezelStyle,
|
||||
NSDisclosureBezelStyle,
|
||||
NSShadowlessSquareBezelStyle,
|
||||
NSCircularBezelStyle,
|
||||
NSTexturedSquareBezelStyle,
|
||||
NSHelpButtonBezelStyle,
|
||||
NSSmallSquareBezelStyle,
|
||||
NSTexturedRoundedBezelStyle,
|
||||
NSRoundRectBezelStyle,
|
||||
NSRecessedBezelStyle,
|
||||
NSRoundedDisclosureBezelStyle,
|
||||
} NSBezelStyle;
|
||||
|
||||
@interface NSButtonCell : NSActionCell {
|
||||
NSString *_alternateTitle;
|
||||
NSImage *_alternateImage;
|
||||
int _imagePosition;
|
||||
unsigned _highlightsBy:4;
|
||||
unsigned _showsStateBy:4;
|
||||
NSBezelStyle _bezelStyle;
|
||||
BOOL _isTransparent;
|
||||
BOOL _imageDimsWhenDisabled;
|
||||
NSString *_keyEquivalent;
|
||||
unsigned _keyEquivalentModifierMask;
|
||||
}
|
||||
|
||||
-(BOOL)isTransparent;
|
||||
-(NSString *)keyEquivalent;
|
||||
-(NSCellImagePosition)imagePosition;
|
||||
-(NSString *)title;
|
||||
-(NSString *)alternateTitle;
|
||||
-(NSImage *)alternateImage;
|
||||
-(NSAttributedString *)attributedTitle;
|
||||
-(NSAttributedString *)attributedAlternateTitle;
|
||||
-(int)highlightsBy;
|
||||
-(int)showsStateBy;
|
||||
-(BOOL)imageDimsWhenDisabled;
|
||||
-(unsigned)keyEquivalentModifierMask;
|
||||
|
||||
-(void)setTransparent:(BOOL)flag;
|
||||
-(void)setKeyEquivalent:(NSString *)keyEquivalent;
|
||||
-(void)setImagePosition:(NSCellImagePosition)position;
|
||||
-(void)setTitle:(NSString *)title;
|
||||
-(void)setAlternateTitle:(NSString *)title;
|
||||
-(void)setAlternateImage:(NSImage *)image;
|
||||
-(void)setAttributedTitle:(NSAttributedString *)title;
|
||||
-(void)setAttributedAlternateTitle:(NSAttributedString *)title;
|
||||
-(void)setHighlightsBy:(int)type;
|
||||
-(void)setShowsStateBy:(int)type;
|
||||
-(void)setImageDimsWhenDisabled:(BOOL)flag;
|
||||
-(void)setKeyEquivalentModifierMask:(unsigned)mask;
|
||||
|
||||
@end
|
||||
|
486
AppKit/NSButtonCell.m
Executable file
486
AppKit/NSButtonCell.m
Executable file
@ -0,0 +1,486 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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>
|
||||
#import <AppKit/NSAttributedString.h>
|
||||
#import <AppKit/NSStringDrawing.h>
|
||||
#import <AppKit/NSGraphicsContext.h>
|
||||
#import <AppKit/NSFont.h>
|
||||
#import <AppKit/NSColor.h>
|
||||
#import <AppKit/NSImage.h>
|
||||
#import <AppKit/NSParagraphStyle.h>
|
||||
#import <AppKit/NSWindow.h>
|
||||
#import <AppKit/NSInterfaceGraphics.h>
|
||||
#import <AppKit/NSStringDrawer.h>
|
||||
#import <AppKit/NSControl.h>
|
||||
#import <AppKit/NSMatrix.h>
|
||||
#import <AppKit/NSNibKeyedUnarchiver.h>
|
||||
|
||||
@implementation NSButtonCell
|
||||
|
||||
-(void)encodeWithCoder:(NSCoder *)coder {
|
||||
[super encodeWithCoder:coder];
|
||||
[coder encodeObject:_title forKey:@"NSButtonCell title"];
|
||||
[coder encodeObject:_alternateTitle forKey:@"NSButtonCell alternateTitle"];
|
||||
[coder encodeInt:_imagePosition forKey:@"NSButtonCell imagePosition"];
|
||||
[coder encodeInt:_highlightsBy forKey:@"NSButtonCell highlightsBy"];
|
||||
[coder encodeInt:_showsStateBy forKey:@"NSButtonCell showsStateBy"];
|
||||
[coder encodeBool:_isTransparent forKey:@"NSButtonCell transparent"];
|
||||
[coder encodeBool:_imageDimsWhenDisabled forKey:@"NSButtonCell imageDimsWhenDisabled"];
|
||||
[coder encodeObject:_alternateImage forKey:@"NSButtonCell alternateImage"];
|
||||
[coder encodeObject:_keyEquivalent forKey:@"NSButtonCell keyEquivalent"];
|
||||
[coder encodeInt:_keyEquivalentModifierMask forKey:@"NSButtonCell keyEquivalentModifierMask"];
|
||||
}
|
||||
|
||||
-initWithCoder:(NSCoder *)coder {
|
||||
[super initWithCoder:coder];
|
||||
|
||||
if([coder isKindOfClass:[NSNibKeyedUnarchiver class]]){
|
||||
NSNibKeyedUnarchiver *keyed=(NSNibKeyedUnarchiver *)coder;
|
||||
unsigned flags=[keyed decodeIntForKey:@"NSButtonFlags"];
|
||||
unsigned flags2=[keyed decodeIntForKey:@"NSButtonFlags2"];
|
||||
|
||||
_title=[[keyed decodeObjectForKey:@"NSContents"] retain];
|
||||
_alternateTitle=[[keyed decodeObjectForKey:@"NSAlternateContents"] retain];
|
||||
|
||||
_imagePosition=NSNoImage;
|
||||
if((flags&0x00480000)==0x00400000)
|
||||
_imagePosition=NSImageOnly;
|
||||
else if((flags&0x00480000)==0x00480000)
|
||||
_imagePosition=NSImageOverlaps;
|
||||
else if((flags&0x00380000)==0x00380000)
|
||||
_imagePosition=NSImageLeft;
|
||||
else if((flags&0x00380000)==0x00280000)
|
||||
_imagePosition=NSImageRight;
|
||||
else if((flags&0x00380000)==0x00180000)
|
||||
_imagePosition=NSImageBelow;
|
||||
else if((flags&0x00380000)==0x00080000)
|
||||
_imagePosition=NSImageAbove;
|
||||
|
||||
_highlightsBy=0;
|
||||
_showsStateBy=0;
|
||||
|
||||
if(flags&0x80000000)
|
||||
_highlightsBy|=NSPushInCellMask;
|
||||
if(flags&0x40000000)
|
||||
_showsStateBy|=NSContentsCellMask;
|
||||
if(flags&0x20000000)
|
||||
_showsStateBy|=NSChangeBackgroundCellMask;
|
||||
if(flags&0x10000000)
|
||||
_showsStateBy|=NSChangeGrayCellMask;
|
||||
if(flags&0x08000000)
|
||||
_highlightsBy|=NSContentsCellMask;
|
||||
if(flags&0x04000000)
|
||||
_highlightsBy|=NSChangeBackgroundCellMask;
|
||||
if(flags&0x02000000)
|
||||
_highlightsBy|=NSChangeGrayCellMask;
|
||||
|
||||
_isBordered=(flags&0x00800000)?YES:NO; // err, this flag is in NSCell too
|
||||
|
||||
switch(flags2&0x37){
|
||||
case 1: _bezelStyle=NSRoundedBezelStyle; break;
|
||||
case 2: _bezelStyle=NSRegularSquareBezelStyle; break;
|
||||
case 3: _bezelStyle=NSThickSquareBezelStyle; break;
|
||||
case 4: _bezelStyle=NSThickerSquareBezelStyle; break;
|
||||
case 5: _bezelStyle=NSDisclosureBezelStyle; break;
|
||||
case 6: _bezelStyle=NSShadowlessSquareBezelStyle; break;
|
||||
case 7: _bezelStyle=NSCircularBezelStyle; break;
|
||||
|
||||
case 32: _bezelStyle=NSTexturedSquareBezelStyle; break;
|
||||
case 33: _bezelStyle=NSHelpButtonBezelStyle; break;
|
||||
case 34: _bezelStyle=NSSmallSquareBezelStyle; break;
|
||||
case 35: _bezelStyle=NSTexturedRoundedBezelStyle; break;
|
||||
case 36: _bezelStyle=NSRoundRectBezelStyle; break;
|
||||
case 37: _bezelStyle=NSRecessedBezelStyle; break;
|
||||
//case 38: _bezelStyle=NSRoundedDisclosureBezelStyle; break; 38 not possible, 31?
|
||||
default: _bezelStyle=NSRoundedBezelStyle; break;
|
||||
}
|
||||
|
||||
_isTransparent=(flags&0x00008000)?YES:NO;
|
||||
_imageDimsWhenDisabled=(flags&0x00002000)?NO:YES;
|
||||
|
||||
_alternateImage=[[keyed decodeObjectForKey:@"NSAlternateImage"] retain];
|
||||
if(![_alternateImage isKindOfClass:[NSImage class]]){
|
||||
[_alternateImage release];
|
||||
_alternateImage=nil;
|
||||
}
|
||||
_keyEquivalent=[[keyed decodeObjectForKey:@"NSKeyEquivalent"] retain];
|
||||
_keyEquivalentModifierMask=flags2>>8;
|
||||
}
|
||||
else {
|
||||
_title=[[coder decodeObjectForKey:@"NSButtonCell title"] retain];
|
||||
_alternateTitle=[[coder decodeObjectForKey:@"NSButtonCell alternateTitle"] retain];
|
||||
_imagePosition=[coder decodeIntForKey:@"NSButtonCell imagePosition"];
|
||||
_highlightsBy=[coder decodeIntForKey:@"NSButtonCell highlightsBy"];
|
||||
_showsStateBy=[coder decodeIntForKey:@"NSButtonCell showsStateBy"];
|
||||
_isTransparent=[coder decodeBoolForKey:@"NSButtonCell transparent"];
|
||||
_imageDimsWhenDisabled=[coder decodeBoolForKey:@"NSButtonCell imageDimsWhenDisabled"];
|
||||
_alternateImage=[[coder decodeObjectForKey:@"NSButtonCell alternateImage"] retain];
|
||||
_keyEquivalent=[[coder decodeObjectForKey:@"NSButtonCell keyEquivalent"] retain];
|
||||
_keyEquivalentModifierMask=[coder decodeIntForKey:@"NSButtonCell keyEquivalentModifierMask"];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-initTextCell:(NSString *)string {
|
||||
[super initTextCell:string];
|
||||
_alternateTitle=@"";
|
||||
_imagePosition=NSNoImage;
|
||||
_highlightsBy=NSPushInCellMask;
|
||||
_showsStateBy=0;
|
||||
_isTransparent=NO;
|
||||
_imageDimsWhenDisabled=NO;
|
||||
_alternateImage=nil;
|
||||
_keyEquivalent=@"";
|
||||
_keyEquivalentModifierMask=0;
|
||||
|
||||
[self setBordered:YES];
|
||||
[self setBezeled:YES];
|
||||
[self setAlignment:NSCenterTextAlignment];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
-initImageCell:(NSImage *)image {
|
||||
[super initImageCell:image];
|
||||
_imagePosition=NSImageOnly;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)dealloc {
|
||||
[_alternateTitle release];
|
||||
[_alternateImage release];
|
||||
[_keyEquivalent release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
-copyWithZone:(NSZone *)zone {
|
||||
NSButtonCell *result=[super copyWithZone:zone];
|
||||
|
||||
result->_alternateTitle =[_alternateTitle copy];
|
||||
result->_alternateImage=[_alternateImage retain];
|
||||
result->_keyEquivalent=[_keyEquivalent copy];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
-(BOOL)isTransparent {
|
||||
return _isTransparent;
|
||||
}
|
||||
|
||||
-(NSString *)keyEquivalent {
|
||||
return _keyEquivalent;
|
||||
}
|
||||
|
||||
-(NSCellImagePosition)imagePosition {
|
||||
return _imagePosition;
|
||||
}
|
||||
|
||||
-(NSString *)title {
|
||||
return _title;
|
||||
}
|
||||
|
||||
-(NSString *)alternateTitle {
|
||||
return _alternateTitle;
|
||||
}
|
||||
|
||||
-(NSImage *)alternateImage {
|
||||
return _alternateImage;
|
||||
}
|
||||
|
||||
-(NSAttributedString *)attributedTitle {
|
||||
NSMutableDictionary *attributes=[NSMutableDictionary dictionary];
|
||||
NSMutableParagraphStyle *paraStyle=[[[NSParagraphStyle defaultParagraphStyle] mutableCopy] autorelease];
|
||||
NSFont *font=[self font];
|
||||
|
||||
if(font!=nil)
|
||||
[attributes setObject:font forKey:NSFontAttributeName];
|
||||
|
||||
if(![self wraps])
|
||||
[paraStyle setLineBreakMode:NSLineBreakByClipping];
|
||||
[paraStyle setAlignment:_textAlignment];
|
||||
[attributes setObject:paraStyle forKey:NSParagraphStyleAttributeName];
|
||||
|
||||
if([self isEnabled])
|
||||
[attributes setObject:[NSColor controlTextColor]
|
||||
forKey:NSForegroundColorAttributeName];
|
||||
else
|
||||
[attributes setObject:[NSColor disabledControlTextColor]
|
||||
forKey:NSForegroundColorAttributeName];
|
||||
|
||||
return [[[NSAttributedString alloc] initWithString:[self title] attributes:attributes] autorelease];
|
||||
}
|
||||
|
||||
-(NSAttributedString *)attributedAlternateTitle {
|
||||
NSMutableDictionary *attributes=[NSMutableDictionary dictionary];
|
||||
NSMutableParagraphStyle *paraStyle=[[[NSParagraphStyle defaultParagraphStyle] mutableCopy] autorelease];
|
||||
NSFont *font=[self font];
|
||||
|
||||
if(font!=nil)
|
||||
[attributes setObject:font forKey:NSFontAttributeName];
|
||||
|
||||
if(![self wraps])
|
||||
[paraStyle setLineBreakMode:NSLineBreakByClipping];
|
||||
[paraStyle setAlignment:_textAlignment];
|
||||
[attributes setObject:paraStyle forKey:NSParagraphStyleAttributeName];
|
||||
|
||||
if([self isEnabled])
|
||||
[attributes setObject:[NSColor controlTextColor]
|
||||
forKey:NSForegroundColorAttributeName];
|
||||
else
|
||||
[attributes setObject:[NSColor disabledControlTextColor]
|
||||
forKey:NSForegroundColorAttributeName];
|
||||
|
||||
|
||||
return [[[NSAttributedString alloc] initWithString:[self alternateTitle] attributes:attributes] autorelease];
|
||||
}
|
||||
|
||||
-(int)highlightsBy {
|
||||
return _highlightsBy;
|
||||
}
|
||||
|
||||
-(int)showsStateBy {
|
||||
return _showsStateBy;
|
||||
}
|
||||
|
||||
-(BOOL)imageDimsWhenDisabled {
|
||||
return _imageDimsWhenDisabled;
|
||||
}
|
||||
|
||||
-(unsigned)keyEquivalentModifierMask {
|
||||
return _keyEquivalentModifierMask;
|
||||
}
|
||||
|
||||
-(int)state {
|
||||
return [self intValue];
|
||||
}
|
||||
|
||||
-(void)setTransparent:(BOOL)flag {
|
||||
_isTransparent=flag;
|
||||
}
|
||||
|
||||
-(void)setKeyEquivalent:(NSString *)keyEquivalent {
|
||||
keyEquivalent=[keyEquivalent copy];
|
||||
[_keyEquivalent release];
|
||||
_keyEquivalent=keyEquivalent;
|
||||
}
|
||||
|
||||
-(void)setImagePosition:(NSCellImagePosition)position {
|
||||
_imagePosition=position;
|
||||
}
|
||||
|
||||
-(void)setTitle:(NSString *)title {
|
||||
title=[title copy];
|
||||
[_title release];
|
||||
_title=title;
|
||||
}
|
||||
|
||||
-(void)setAlternateTitle:(NSString *)title {
|
||||
title=[title copy];
|
||||
[_alternateTitle release];
|
||||
_alternateTitle=title;
|
||||
}
|
||||
|
||||
-(void)setAlternateImage:(NSImage *)image {
|
||||
image=[image retain];
|
||||
[_alternateImage release];
|
||||
_alternateImage=image;
|
||||
}
|
||||
|
||||
-(void)setAttributedTitle:(NSAttributedString *)title {
|
||||
NSUnimplementedMethod();
|
||||
}
|
||||
|
||||
-(void)setAttributedAlternateTitle:(NSAttributedString *)title {
|
||||
NSUnimplementedMethod();
|
||||
}
|
||||
|
||||
-(void)setHighlightsBy:(int)type {
|
||||
_highlightsBy=type;
|
||||
}
|
||||
|
||||
-(void)setShowsStateBy:(int)type {
|
||||
_showsStateBy=type;
|
||||
}
|
||||
|
||||
-(void)setImageDimsWhenDisabled:(BOOL)flag {
|
||||
_imageDimsWhenDisabled=flag;
|
||||
}
|
||||
|
||||
-(void)setKeyEquivalentModifierMask:(unsigned)mask {
|
||||
_keyEquivalentModifierMask=mask;
|
||||
}
|
||||
|
||||
-(void)setState:(int)value {
|
||||
[self setIntValue:value];
|
||||
}
|
||||
|
||||
|
||||
-(NSAttributedString *)titleForHighlight {
|
||||
if((([self highlightsBy]&NSContentsCellMask) && [self isHighlighted]) ||
|
||||
(([self showsStateBy]&NSContentsCellMask) && [self state])){
|
||||
NSAttributedString *result=[self attributedAlternateTitle];
|
||||
|
||||
if([result length]>0)
|
||||
return result;
|
||||
}
|
||||
|
||||
return [self attributedTitle];
|
||||
}
|
||||
|
||||
-(NSImage *)imageForHighlight {
|
||||
if((([self highlightsBy]&NSContentsCellMask) && [self isHighlighted]) ||
|
||||
(([self showsStateBy]&NSContentsCellMask) && [self state]))
|
||||
return [self alternateImage];
|
||||
|
||||
return [self image];
|
||||
}
|
||||
|
||||
-(BOOL)isVisuallyHighlighted {
|
||||
return ((([self highlightsBy]&NSChangeGrayCellMask) && [self isHighlighted]) ||
|
||||
(([self showsStateBy]&NSChangeGrayCellMask) && [self state]));
|
||||
}
|
||||
|
||||
-(void)drawInteriorWithFrame:(NSRect)frame inView:(NSView *)controlView {
|
||||
NSAttributedString *title=[self titleForHighlight];
|
||||
NSImage *image=[self imageForHighlight];
|
||||
NSSize imageSize=(image==nil)?NSMakeSize(0,0):[image size];
|
||||
NSPoint imageOrigin=frame.origin;
|
||||
NSSize titleSize=[title size];
|
||||
NSRect titleRect=frame;
|
||||
BOOL drawImage=YES,drawTitle=YES;
|
||||
|
||||
if([self isTransparent])
|
||||
return;
|
||||
|
||||
imageOrigin.x+=floor((frame.size.width-imageSize.width)/2);
|
||||
imageOrigin.y+=floor((frame.size.height-imageSize.height)/2);
|
||||
|
||||
titleRect.origin.y+=floor((titleRect.size.height-titleSize.height)/2);
|
||||
titleRect.size.height=titleSize.height;
|
||||
|
||||
switch([self imagePosition]){
|
||||
|
||||
case NSNoImage:
|
||||
drawImage=NO;
|
||||
break;
|
||||
|
||||
case NSImageOnly:
|
||||
drawTitle=NO;
|
||||
break;
|
||||
|
||||
case NSImageLeft:
|
||||
imageOrigin.x=frame.origin.x;
|
||||
titleRect.origin.x+=imageSize.width+2;
|
||||
titleRect.size.width-=imageSize.width+2;
|
||||
break;
|
||||
|
||||
case NSImageRight:
|
||||
imageOrigin.x=frame.origin.x+(frame.size.width-imageSize.width);
|
||||
titleRect.size.width-=(imageSize.width+2);
|
||||
break;
|
||||
|
||||
case NSImageBelow:
|
||||
imageOrigin.y=frame.origin.y;
|
||||
titleRect.origin.y+=imageSize.height;
|
||||
break;
|
||||
|
||||
case NSImageAbove:
|
||||
imageOrigin.y=frame.origin.y+(frame.size.height-imageSize.height);
|
||||
titleRect.origin.y-=imageSize.height;
|
||||
if(titleRect.origin.y<frame.origin.y)
|
||||
titleRect.origin.y=frame.origin.y;
|
||||
break;
|
||||
|
||||
case NSImageOverlaps:
|
||||
break;
|
||||
}
|
||||
|
||||
if(![self isBordered]){
|
||||
if([self isVisuallyHighlighted]){
|
||||
[[NSColor whiteColor] set];
|
||||
NSRectFill(frame);
|
||||
}
|
||||
else {
|
||||
[[NSColor controlColor] set];
|
||||
NSRectFill(frame);
|
||||
}
|
||||
}
|
||||
|
||||
if([self isBordered]){
|
||||
if(([self highlightsBy]&NSPushInCellMask) && [self isHighlighted]){
|
||||
imageOrigin.x+=1;
|
||||
imageOrigin.y+=[controlView isFlipped]?1:-1;
|
||||
titleRect.origin.x+=1;
|
||||
titleRect.origin.y+=[controlView isFlipped]?1:-1;
|
||||
}
|
||||
}
|
||||
|
||||
if(drawImage){
|
||||
float dimFraction=[self imageDimsWhenDisabled]?0.5:1.0;
|
||||
|
||||
[image compositeToPoint:imageOrigin operation:NSCompositeSourceOver fraction:[self isEnabled]?1.0:dimFraction];
|
||||
}
|
||||
|
||||
if(drawTitle){
|
||||
BOOL drawDottedRect=NO;
|
||||
|
||||
[title _clipAndDrawInRect:titleRect];
|
||||
|
||||
if([[controlView window] firstResponder]==controlView){
|
||||
|
||||
if([controlView isKindOfClass:[NSMatrix class]]){
|
||||
NSMatrix *matrix=(NSMatrix *)controlView;
|
||||
|
||||
drawDottedRect=([matrix keyCell]==self)?YES:NO;
|
||||
}
|
||||
else if([controlView isKindOfClass:[NSControl class]]){
|
||||
NSControl *control=(NSControl *)controlView;
|
||||
|
||||
drawDottedRect=([control selectedCell]==self)?YES:NO;
|
||||
}
|
||||
}
|
||||
|
||||
if(drawDottedRect)
|
||||
NSDottedFrameRect(NSInsetRect(titleRect,1,1));
|
||||
}
|
||||
}
|
||||
|
||||
-(void)drawWithFrame:(NSRect)frame inView:(NSView *)control {
|
||||
_controlView=control;
|
||||
|
||||
if([self isTransparent])
|
||||
return;
|
||||
|
||||
if ([[control window] defaultButtonCell] == self) {
|
||||
[[NSColor blackColor] set];
|
||||
NSRectFill(frame);
|
||||
frame = NSInsetRect(frame,1,1);
|
||||
}
|
||||
|
||||
if([self isBordered]){
|
||||
if(([self highlightsBy]&NSPushInCellMask) && [self isHighlighted]){
|
||||
NSInterfaceDrawDepressedButton(frame,frame);
|
||||
}
|
||||
else {
|
||||
if([self isVisuallyHighlighted])
|
||||
NSInterfaceDrawHighlightedButton(frame,frame);
|
||||
else
|
||||
NSDrawButton(frame,frame);
|
||||
}
|
||||
|
||||
frame=NSInsetRect(frame,2,2);
|
||||
}
|
||||
|
||||
[self drawInteriorWithFrame:frame inView:control];
|
||||
}
|
||||
|
||||
@end
|
21
AppKit/NSCachedImageRep.h
Executable file
21
AppKit/NSCachedImageRep.h
Executable file
@ -0,0 +1,21 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/NSImageRep.h>
|
||||
|
||||
@class CGRenderingContext;
|
||||
|
||||
@interface NSCachedImageRep : NSImageRep {
|
||||
CGRenderingContext *_renderingContext;
|
||||
}
|
||||
|
||||
-initWithSize:(NSSize)size;
|
||||
|
||||
-(CGRenderingContext *)renderingContext;
|
||||
|
||||
@end
|
37
AppKit/NSCachedImageRep.m
Executable file
37
AppKit/NSCachedImageRep.m
Executable file
@ -0,0 +1,37 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/NSCachedImageRep.h>
|
||||
#import <AppKit/CGRenderingContext.h>
|
||||
#import <AppKit/NSGraphicsContextFunctions.h>
|
||||
#import <AppKit/NSDisplay.h>
|
||||
|
||||
@implementation NSCachedImageRep
|
||||
|
||||
-initWithSize:(NSSize)size {
|
||||
_size=size;
|
||||
_renderingContext=[[[NSDisplay currentDisplay] bitmapRenderingContextWithSize:size] retain];
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)dealloc {
|
||||
[_renderingContext release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
-(CGRenderingContext *)renderingContext {
|
||||
return _renderingContext;
|
||||
}
|
||||
|
||||
-(BOOL)drawAtPoint:(NSPoint)point {
|
||||
CGContextBitCopy(NSCurrentGraphicsPort(),point,_renderingContext,NSMakePoint(0,0),_size);
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
170
AppKit/NSCell.h
Executable file
170
AppKit/NSCell.h
Executable file
@ -0,0 +1,170 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/NSText.h>
|
||||
|
||||
@class NSFont,NSImage,NSView;
|
||||
|
||||
typedef enum {
|
||||
NSNullCellType,
|
||||
NSTextCellType,
|
||||
NSImageCellType
|
||||
} NSCellType;
|
||||
|
||||
enum {
|
||||
NSAnyType=0,
|
||||
NSIntType=1,
|
||||
NSPositiveIntType=2,
|
||||
NSFloatType=3,
|
||||
NSPositiveFloatType=4,
|
||||
NSDoubleType=6,
|
||||
NSPositiveDoubleType=7
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
NSNoImage,
|
||||
NSImageOnly,
|
||||
NSImageLeft,
|
||||
NSImageRight,
|
||||
NSImageBelow,
|
||||
NSImageAbove,
|
||||
NSImageOverlaps
|
||||
} NSCellImagePosition;
|
||||
|
||||
typedef enum {
|
||||
NSMixedState=-1,
|
||||
NSOffState=0,
|
||||
NSOnState=1,
|
||||
} NSCellState;
|
||||
|
||||
@interface NSCell : NSObject <NSCopying,NSCoding> {
|
||||
int _state;
|
||||
NSFont *_font;
|
||||
int _entryType;
|
||||
id _objectValue;
|
||||
NSImage *_image;
|
||||
int _textAlignment;
|
||||
int _cellType;
|
||||
NSFormatter *_formatter;
|
||||
NSString *_title;
|
||||
id _representedObject;
|
||||
|
||||
BOOL _isEnabled;
|
||||
BOOL _isEditable;
|
||||
BOOL _isSelectable;
|
||||
BOOL _isScrollable;
|
||||
BOOL _wraps;
|
||||
BOOL _isBordered;
|
||||
BOOL _isBezeled;
|
||||
BOOL _isHighlighted;
|
||||
BOOL _refusesFirstResponder;
|
||||
BOOL _isContinuous;
|
||||
}
|
||||
|
||||
-initTextCell:(NSString *)string;
|
||||
-initImageCell:(NSImage *)image;
|
||||
|
||||
-(NSView *)controlView;
|
||||
-(NSCellType)type;
|
||||
-(int)state;
|
||||
|
||||
-target;
|
||||
-(SEL)action;
|
||||
-(int)tag;
|
||||
-(int)entryType;
|
||||
-(id)formatter;
|
||||
-(NSFont *)font;
|
||||
-(NSImage *)image;
|
||||
-(NSTextAlignment)alignment;
|
||||
-(BOOL)wraps;
|
||||
-(NSString *)title;
|
||||
|
||||
-(BOOL)isEnabled;
|
||||
-(BOOL)isEditable;
|
||||
-(BOOL)isSelectable;
|
||||
-(BOOL)isScrollable;
|
||||
-(BOOL)isBordered;
|
||||
-(BOOL)isBezeled;
|
||||
-(BOOL)isContinuous;
|
||||
-(BOOL)refusesFirstResponder;
|
||||
-(BOOL)isHighlighted;
|
||||
|
||||
-objectValue;
|
||||
-(NSString *)stringValue;
|
||||
-(int)intValue;
|
||||
-(float)floatValue;
|
||||
-(double)doubleValue;
|
||||
-(NSAttributedString *)attributedStringValue;
|
||||
-(id)representedObject;
|
||||
|
||||
-(void)setType:(NSCellType)type;
|
||||
|
||||
-(void)setState:(int)value;
|
||||
-(int)nextState;
|
||||
|
||||
-(void)setTarget:target;
|
||||
-(void)setAction:(SEL)action;
|
||||
-(void)setTag:(int)tag;
|
||||
-(void)setEntryType:(int)type;
|
||||
-(void)setFormatter:(NSFormatter *)formatter;
|
||||
-(void)setFont:(NSFont *)font;
|
||||
-(void)setImage:(NSImage *)image;
|
||||
-(void)setAlignment:(NSTextAlignment)alignment;
|
||||
-(void)setWraps:(BOOL)wraps;
|
||||
-(void)setTitle:(NSString *)title;
|
||||
|
||||
-(void)setEnabled:(BOOL)flag;
|
||||
-(void)setEditable:(BOOL)flag;
|
||||
-(void)setSelectable:(BOOL)flag;
|
||||
-(void)setScrollable:(BOOL)flag;
|
||||
-(void)setBordered:(BOOL)flag;
|
||||
-(void)setBezeled:(BOOL)flag;
|
||||
-(void)setContinuous:(BOOL)flag;
|
||||
-(void)setRefusesFirstResponder:(BOOL)flag;
|
||||
-(void)setHighlighted:(BOOL)flag;
|
||||
|
||||
-(void)setFloatingPointFormat:(BOOL)fpp left:(unsigned)left right:(unsigned)right;
|
||||
|
||||
-(void)setObjectValue:(id <NSCopying>)value;
|
||||
-(void)setStringValue:(NSString *)value;
|
||||
-(void)setIntValue:(int)value;
|
||||
-(void)setFloatValue:(float)value;
|
||||
-(void)setDoubleValue:(double)value;
|
||||
-(void)setAttributedStringValue:(NSAttributedString *)value;
|
||||
-(void)setRepresentedObject:(id)object;
|
||||
|
||||
-(void)takeObjectValueFrom:sender;
|
||||
-(void)takeStringValueFrom:sender;
|
||||
-(void)takeIntValueFrom:sender;
|
||||
-(void)takeFloatValueFrom:sender;
|
||||
|
||||
-(NSSize)cellSize;
|
||||
|
||||
-(NSRect)imageRectForBounds:(NSRect)rect;
|
||||
-(NSRect)titleRectForBounds:(NSRect)rect;
|
||||
-(NSRect)drawingRectForBounds:(NSRect)rect;
|
||||
|
||||
-(void)drawInteriorWithFrame:(NSRect)frame inView:(NSView *)view;
|
||||
-(void)drawWithFrame:(NSRect)frame inView:(NSView *)view;
|
||||
|
||||
-(void)highlight:(BOOL)highlight withFrame:(NSRect)frame inView:(NSView *)view;
|
||||
|
||||
-(BOOL)startTrackingAt:(NSPoint)startPoint inView:(NSView *)view;
|
||||
-(BOOL)continueTracking:(NSPoint)lastPoint at:(NSPoint)currentPoint inView:(NSView *)view;
|
||||
-(void)stopTracking:(NSPoint)lastPoint at:(NSPoint)stopPoint inView:(NSView *)view mouseIsUp:(BOOL)flag;
|
||||
-(BOOL)trackMouse:(NSEvent *)event inRect:(NSRect)frame ofView:(NSView *)view untilMouseUp:(BOOL)flag;
|
||||
|
||||
-(NSText *)setUpFieldEditorAttributes:(NSText *)editor;
|
||||
|
||||
-(void)editWithFrame:(NSRect)frame inView:(NSView *)view editor:(NSText *)editor delegate:(id)delegate event:(NSEvent *)event;
|
||||
-(void)selectWithFrame:(NSRect)frame inView:(NSView *)view editor:(NSText *)editor delegate:(id)delegate start:(int)location length:(int)length;
|
||||
-(void)endEditing:(NSText *)editor;
|
||||
|
||||
-(void)resetCursorRect:(NSRect)rect inView:(NSView *)view;
|
||||
|
||||
@end
|
720
AppKit/NSCell.m
Executable file
720
AppKit/NSCell.m
Executable file
@ -0,0 +1,720 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/NSCell.h>
|
||||
#import <AppKit/NSFont.h>
|
||||
#import <AppKit/NSImage.h>
|
||||
#import <AppKit/NSWindow.h>
|
||||
#import <AppKit/NSEvent.h>
|
||||
#import <AppKit/NSParagraphStyle.h>
|
||||
#import <AppKit/NSAttributedString.h>
|
||||
#import <AppKit/NSColor.h>
|
||||
#import <AppKit/NSCursor.h>
|
||||
#import <AppKit/NSControl.h>
|
||||
#import <AppKit/NSClipView.h>
|
||||
#import <AppKit/NSNibKeyedUnarchiver.h>
|
||||
|
||||
#import <Foundation/NSNumberFormatter.h>
|
||||
|
||||
@implementation NSCell
|
||||
|
||||
-(void)encodeWithCoder:(NSCoder *)coder {
|
||||
[coder encodeInt:_state forKey:@"NSCell state"];
|
||||
[coder encodeInt:_cellType forKey:@"NSCell type"];
|
||||
[coder encodeInt:_textAlignment forKey:@"NSCell alignment"];
|
||||
[coder encodeBool:_wraps forKey:@"NSCell wraps"];
|
||||
[coder encodeBool:_isEnabled forKey:@"NSCell enabled"];
|
||||
[coder encodeBool:_isEditable forKey:@"NSCell editable"];
|
||||
[coder encodeBool:_isSelectable forKey:@"NSCell selectable"];
|
||||
[coder encodeBool:_isScrollable forKey:@"NSCell scrollable"];
|
||||
[coder encodeBool:_isBordered forKey:@"NSCell bordered"];
|
||||
[coder encodeBool:_isBezeled forKey:@"NSCell bezeled"];
|
||||
[coder encodeBool:_isHighlighted forKey:@"NSCell highlighted"];
|
||||
[coder encodeBool:_isContinuous forKey:@"NSCell continuous"];
|
||||
[coder encodeObject:_font forKey:@"NSCell font"];
|
||||
[coder encodeObject:_objectValue forKey:@"NSCell objectValue"];
|
||||
[coder encodeObject:_image forKey:@"NSCell image"];
|
||||
}
|
||||
|
||||
-initWithCoder:(NSCoder *)coder {
|
||||
if([coder isKindOfClass:[NSNibKeyedUnarchiver class]]){
|
||||
NSNibKeyedUnarchiver *keyed=(NSNibKeyedUnarchiver *)coder;
|
||||
int flags=[keyed decodeIntForKey:@"NSCellFlags"];
|
||||
int flags2=[keyed decodeIntForKey:@"NSCellFlags2"];
|
||||
|
||||
_state=(flags&0x8000000)?YES:NO;
|
||||
_isHighlighted=(flags&0x40000000)?YES:NO;
|
||||
_isEnabled=(flags&0x20000000)?NO:YES;
|
||||
_isEditable=(flags&0x10000000)?YES:NO;
|
||||
_cellType=(flags&0x0C000000)>>26;
|
||||
_isBordered=(flags&0x00800000)?YES:NO;
|
||||
_isBezeled=(flags&0x00400000)?YES:NO;
|
||||
_isSelectable=(flags&0x00200000)?YES:NO;
|
||||
_isScrollable=(flags&0x00100000)?YES:NO;
|
||||
_wraps=(flags&0x00100000)?NO:YES; // ! scrollable, use lineBreakMode ?
|
||||
// 0x00080000 = continuous
|
||||
// 0x00040000 = action on mouse down
|
||||
// 0x00000100 = action on mouse drag
|
||||
_isContinuous=(flags&0x00080100)?YES:NO;
|
||||
_textAlignment=(flags2&0x1c000000)>>26;
|
||||
_objectValue=[[keyed decodeObjectForKey:@"NSContents"] retain];
|
||||
_image=[[keyed decodeObjectForKey:@"NSNormalImage"] retain];
|
||||
if([_image isKindOfClass:[NSFont class]]){
|
||||
_font=(NSFont *)_image;
|
||||
_image=nil;
|
||||
}
|
||||
else {
|
||||
_font=[[keyed decodeObjectForKey:@"NSSupport"] retain];
|
||||
if(![_font isKindOfClass:[NSFont class]]){
|
||||
[_font release];
|
||||
_font=nil;
|
||||
}
|
||||
if(_font==nil)
|
||||
_font=[[NSFont userFontOfSize:0] retain]; // ?
|
||||
}
|
||||
}
|
||||
else {
|
||||
_state=[coder decodeIntForKey:@"NSCell state"];
|
||||
_cellType=[coder decodeIntForKey:@"NSCell type"];
|
||||
_textAlignment=[coder decodeIntForKey:@"NSCell alignment"];
|
||||
_wraps=[coder decodeBoolForKey:@"NSCell wraps"];
|
||||
_isEnabled=[coder decodeBoolForKey:@"NSCell enabled"];
|
||||
_isEditable=[coder decodeBoolForKey:@"NSCell editable"];
|
||||
_isSelectable=[coder decodeBoolForKey:@"NSCell selectable"];
|
||||
_isScrollable=[coder decodeBoolForKey:@"NSCell scrollable"];
|
||||
_isBordered=[coder decodeBoolForKey:@"NSCell bordered"];
|
||||
_isBezeled=[coder decodeBoolForKey:@"NSCell bezeled"];
|
||||
_isHighlighted=[coder decodeBoolForKey:@"NSCell highlighted"];
|
||||
_isContinuous=[coder decodeBoolForKey:@"NSCell continuous"];
|
||||
_font=[[coder decodeObjectForKey:@"NSCell font"] retain];
|
||||
_objectValue=[[coder decodeObjectForKey:@"NSCell objectValue"] retain];
|
||||
_image=[[coder decodeObjectForKey:@"NSCell image"] retain];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-initTextCell:(NSString *)string {
|
||||
|
||||
_state=NSOffState;
|
||||
_font=[[NSFont userFontOfSize:0] retain];
|
||||
_objectValue=[string copy];
|
||||
_image=nil;
|
||||
_cellType=NSTextCellType;
|
||||
_isEnabled=YES;
|
||||
_isEditable=NO;
|
||||
_isSelectable=NO;
|
||||
_wraps=NO;
|
||||
_isBordered=NO;
|
||||
_isBezeled=NO;
|
||||
_isHighlighted=NO;
|
||||
_refusesFirstResponder=NO;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
-initImageCell:(NSImage *)image {
|
||||
|
||||
_state=NSOffState;
|
||||
_font=nil;
|
||||
_objectValue=nil;
|
||||
_image=[image retain];
|
||||
_cellType=NSImageCellType;
|
||||
_isEnabled=YES;
|
||||
_isEditable=NO;
|
||||
_isSelectable=NO;
|
||||
_wraps=NO;
|
||||
_isBordered=NO;
|
||||
_isBezeled=NO;
|
||||
_isHighlighted=NO;
|
||||
_refusesFirstResponder=NO;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
-init {
|
||||
return [self initTextCell:@"Cell"];
|
||||
}
|
||||
|
||||
-(void)dealloc {
|
||||
[_font release];
|
||||
[_objectValue release];
|
||||
[_image release];
|
||||
[_formatter release];
|
||||
[_title release];
|
||||
[_representedObject release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
-copyWithZone:(NSZone *)zone {
|
||||
NSCell *copy=NSCopyObject(self,0,zone);
|
||||
|
||||
copy->_font=[_font retain];
|
||||
copy->_objectValue=[_objectValue copy];
|
||||
copy->_image=[_image retain];
|
||||
copy->_formatter=[_formatter retain];
|
||||
copy->_title=[_title retain];
|
||||
copy->_representedObject=[_representedObject retain];
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
-(NSView *)controlView {
|
||||
return nil;
|
||||
}
|
||||
|
||||
-(NSCellType)type {
|
||||
return _cellType;
|
||||
}
|
||||
|
||||
-(int)state {
|
||||
return _state;
|
||||
}
|
||||
|
||||
-target {
|
||||
return nil;
|
||||
}
|
||||
|
||||
-(SEL)action {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
-(int)tag {
|
||||
return -1;
|
||||
}
|
||||
|
||||
-(int)entryType {
|
||||
return _entryType;
|
||||
}
|
||||
|
||||
-(id)formatter {
|
||||
return _formatter;
|
||||
}
|
||||
|
||||
-(NSFont *)font {
|
||||
return _font;
|
||||
}
|
||||
|
||||
-(NSImage *)image {
|
||||
return _image;
|
||||
}
|
||||
|
||||
-(NSTextAlignment)alignment {
|
||||
return _textAlignment;
|
||||
}
|
||||
|
||||
-(BOOL)wraps {
|
||||
return _wraps;
|
||||
}
|
||||
|
||||
-(NSString *)title {
|
||||
return _title;
|
||||
}
|
||||
|
||||
-(BOOL)isEnabled {
|
||||
return _isEnabled;
|
||||
}
|
||||
|
||||
-(BOOL)isEditable {
|
||||
return _isEditable;
|
||||
}
|
||||
|
||||
-(BOOL)isSelectable {
|
||||
return _isSelectable;
|
||||
}
|
||||
|
||||
-(BOOL)isScrollable {
|
||||
return _isScrollable;
|
||||
}
|
||||
|
||||
-(BOOL)isBordered {
|
||||
return _isBordered;
|
||||
}
|
||||
|
||||
-(BOOL)isBezeled {
|
||||
return _isBezeled;
|
||||
}
|
||||
|
||||
-(BOOL)isContinuous {
|
||||
return _isContinuous;
|
||||
}
|
||||
|
||||
-(BOOL)refusesFirstResponder {
|
||||
return _refusesFirstResponder;
|
||||
}
|
||||
|
||||
-(BOOL)isHighlighted {
|
||||
return _isHighlighted;
|
||||
}
|
||||
|
||||
-objectValue {
|
||||
return _objectValue;
|
||||
}
|
||||
|
||||
-(NSString *)stringValue {
|
||||
NSString *formatted;
|
||||
|
||||
if (_formatter != nil)
|
||||
if (formatted = [_formatter stringForObjectValue:_objectValue])
|
||||
return formatted;
|
||||
|
||||
if([_objectValue isKindOfClass:[NSAttributedString class]])
|
||||
return [_objectValue string];
|
||||
|
||||
return [_objectValue description];
|
||||
}
|
||||
|
||||
-(int)intValue {
|
||||
return [_objectValue intValue];
|
||||
}
|
||||
|
||||
-(float)floatValue {
|
||||
return [_objectValue floatValue];
|
||||
}
|
||||
|
||||
-(double)doubleValue {
|
||||
return [_objectValue doubleValue];
|
||||
}
|
||||
|
||||
-(NSAttributedString *)attributedStringValue {
|
||||
if([_objectValue isKindOfClass:[NSAttributedString class]])
|
||||
return _objectValue;
|
||||
else {
|
||||
NSMutableDictionary *attributes=[NSMutableDictionary dictionary];
|
||||
NSMutableParagraphStyle *paraStyle=[[[NSParagraphStyle defaultParagraphStyle] mutableCopy] autorelease];
|
||||
NSFont *font=[self font];
|
||||
|
||||
if(font!=nil)
|
||||
[attributes setObject:font forKey:NSFontAttributeName];
|
||||
|
||||
if([self isEnabled]){
|
||||
if([self isHighlighted] || [self state])
|
||||
[attributes setObject:[NSColor whiteColor]
|
||||
forKey:NSForegroundColorAttributeName];
|
||||
else
|
||||
[attributes setObject:[NSColor controlTextColor]
|
||||
forKey:NSForegroundColorAttributeName];
|
||||
}
|
||||
else {
|
||||
[attributes setObject:[NSColor disabledControlTextColor]
|
||||
forKey:NSForegroundColorAttributeName];
|
||||
}
|
||||
|
||||
if(![self wraps])
|
||||
[paraStyle setLineBreakMode:NSLineBreakByClipping];
|
||||
[paraStyle setAlignment:_textAlignment];
|
||||
[attributes setObject:paraStyle forKey:NSParagraphStyleAttributeName];
|
||||
|
||||
return [[[NSAttributedString alloc] initWithString:[self stringValue] attributes:attributes] autorelease];
|
||||
}
|
||||
}
|
||||
|
||||
-(id)representedObject {
|
||||
return _representedObject;
|
||||
}
|
||||
|
||||
-(void)setType:(NSCellType)type {
|
||||
if(_cellType!=type){
|
||||
_cellType = type;
|
||||
if (type == NSTextCellType) {
|
||||
// FIX, localization
|
||||
[self setTitle:@"Cell"]; // mostly clarified in setEntryType dox
|
||||
[self setFont:[NSFont systemFontOfSize:12.0]];
|
||||
}
|
||||
[[[self controlView] window] invalidateCursorRectsForView:[self controlView]];
|
||||
}
|
||||
}
|
||||
|
||||
-(void)setState:(int)value {
|
||||
_state=value;
|
||||
}
|
||||
|
||||
-(int)nextState {
|
||||
return ([self state]==0)?1:0;
|
||||
}
|
||||
|
||||
-(void)setTarget:target {
|
||||
[NSException raise:NSInternalInconsistencyException
|
||||
format:@"-[%@ %s] Unimplemented",isa,SELNAME(_cmd)];
|
||||
}
|
||||
|
||||
|
||||
-(void)setAction:(SEL)action {
|
||||
[NSException raise:NSInternalInconsistencyException
|
||||
format:@"-[%@ %s] Unimplemented",isa,SELNAME(_cmd)];
|
||||
}
|
||||
|
||||
-(void)setTag:(int)tag {
|
||||
[NSException raise:NSInternalInconsistencyException
|
||||
format:@"-[%@ %s] Unimplemented",isa,SELNAME(_cmd)];
|
||||
}
|
||||
|
||||
-(void)setEntryType:(int)type {
|
||||
_entryType=type;
|
||||
[self setType:NSTextCellType];
|
||||
}
|
||||
|
||||
-(void)setFormatter:(NSFormatter *)formatter {
|
||||
formatter=[formatter retain];
|
||||
[_formatter release];
|
||||
_formatter=formatter;
|
||||
}
|
||||
|
||||
-(void)setFont:(NSFont *)font {
|
||||
font=[font retain];
|
||||
[_font release];
|
||||
_font=font;
|
||||
}
|
||||
|
||||
-(void)setImage:(NSImage *)image {
|
||||
[self setType:NSImageCellType];
|
||||
image=[image retain];
|
||||
[_image release];
|
||||
_image=image;
|
||||
[(NSControl *)[self controlView] updateCell:self];
|
||||
}
|
||||
|
||||
-(void)setAlignment:(NSTextAlignment)alignment {
|
||||
_textAlignment=alignment;
|
||||
}
|
||||
|
||||
-(void)setWraps:(BOOL)wraps {
|
||||
_wraps=wraps;
|
||||
}
|
||||
|
||||
-(void)setTitle:(NSString *)title {
|
||||
title = [title retain];
|
||||
[_title release];
|
||||
_title = title;
|
||||
}
|
||||
|
||||
-(void)setEnabled:(BOOL)flag {
|
||||
if(_isEnabled!=flag){
|
||||
_isEnabled=flag;
|
||||
[(NSControl *)[self controlView] updateCell:self];
|
||||
[[[self controlView] window] invalidateCursorRectsForView:[self controlView]];
|
||||
}
|
||||
}
|
||||
|
||||
-(void)setEditable:(BOOL)flag {
|
||||
if(_isEditable!=flag){
|
||||
_isEditable=flag;
|
||||
[[[self controlView] window] invalidateCursorRectsForView:[self controlView]];
|
||||
}
|
||||
}
|
||||
|
||||
-(void)setSelectable:(BOOL)flag {
|
||||
if(_isSelectable!=flag){
|
||||
_isSelectable=flag;
|
||||
[[[self controlView] window] invalidateCursorRectsForView:[self controlView]];
|
||||
}
|
||||
}
|
||||
|
||||
-(void)setScrollable:(BOOL)flag {
|
||||
_isScrollable=flag;
|
||||
}
|
||||
|
||||
-(void)setBordered:(BOOL)flag {
|
||||
_isBordered=flag;
|
||||
}
|
||||
|
||||
-(void)setBezeled:(BOOL)flag {
|
||||
_isBezeled=flag;
|
||||
}
|
||||
|
||||
-(void)setContinuous:(BOOL)flag {
|
||||
_isContinuous=flag;
|
||||
}
|
||||
|
||||
-(void)setRefusesFirstResponder:(BOOL)flag {
|
||||
_refusesFirstResponder=flag;
|
||||
}
|
||||
|
||||
-(void)setHighlighted:(BOOL)flag {
|
||||
_isHighlighted = flag;
|
||||
}
|
||||
|
||||
// the problem with this method is that the dox specify that if autorange is YES, then the field
|
||||
// becomes one big floating-point entry, but NSNumberFormatter doesn't work that way. - dwy
|
||||
-(void)setFloatingPointFormat:(BOOL)fpp left:(unsigned)left right:(unsigned)right {
|
||||
NSMutableString *format = [NSMutableString string];
|
||||
|
||||
[self setFormatter:[[[NSNumberFormatter alloc] init] autorelease]];
|
||||
if (fpp == YES) { // autorange
|
||||
unsigned fieldWidth = left + right;
|
||||
while(fieldWidth--)
|
||||
[format appendString:@"#"];
|
||||
}
|
||||
else {
|
||||
while(left--)
|
||||
[format appendString:@"#"];
|
||||
[format appendString:@"."];
|
||||
while(right--)
|
||||
[format appendString:@"0"];
|
||||
}
|
||||
[(NSNumberFormatter *)_formatter setFormat:format];
|
||||
}
|
||||
|
||||
-(void)setObjectValue:(id <NSCopying>)value {
|
||||
value=[value copyWithZone:NULL];
|
||||
[_objectValue release];
|
||||
_objectValue=value;
|
||||
[(NSControl *)[self controlView] updateCell:self];
|
||||
}
|
||||
|
||||
-(void)setStringValue:(NSString *)value {
|
||||
if(value==nil){
|
||||
[NSException raise:NSInvalidArgumentException format:@"-[%@ %s] value==nil",isa,SELNAME(_cmd)];
|
||||
return;
|
||||
}
|
||||
|
||||
[self setType:NSTextCellType];
|
||||
|
||||
if (_formatter != nil) {
|
||||
id formattedValue;
|
||||
|
||||
if ([_formatter getObjectValue:&formattedValue forString:value errorDescription:NULL])
|
||||
value=formattedValue;
|
||||
}
|
||||
|
||||
[self setObjectValue:value];
|
||||
}
|
||||
|
||||
-(void)setIntValue:(int)value {
|
||||
[self setObjectValue:[NSNumber numberWithInt:value]];
|
||||
}
|
||||
|
||||
-(void)setFloatValue:(float)value {
|
||||
[self setObjectValue:[NSNumber numberWithFloat:value]];
|
||||
}
|
||||
|
||||
-(void)setDoubleValue:(double)value {
|
||||
[self setObjectValue:[NSNumber numberWithDouble:value]];
|
||||
}
|
||||
|
||||
-(void)setAttributedStringValue:(NSAttributedString *)value {
|
||||
value=[value copy];
|
||||
[_objectValue release];
|
||||
_objectValue=value;
|
||||
}
|
||||
|
||||
-(void)setRepresentedObject:(id)object {
|
||||
object = [object retain];
|
||||
[_representedObject release];
|
||||
_representedObject = object;
|
||||
}
|
||||
|
||||
-(void)takeObjectValueFrom:sender {
|
||||
[self setObjectValue:[sender objectValue]];
|
||||
}
|
||||
|
||||
-(void)takeStringValueFrom:sender {
|
||||
[self setStringValue:[sender stringValue]];
|
||||
}
|
||||
|
||||
-(void)takeIntValueFrom:sender {
|
||||
[self setIntValue:[sender intValue]];
|
||||
}
|
||||
|
||||
-(void)takeFloatValueFrom:sender {
|
||||
[self setFloatValue:[sender floatValue]];
|
||||
}
|
||||
|
||||
-(NSSize)cellSize {
|
||||
NSUnimplementedMethod();
|
||||
return NSMakeSize(0,0);
|
||||
}
|
||||
|
||||
-(NSRect)imageRectForBounds:(NSRect)rect {
|
||||
return rect;
|
||||
}
|
||||
|
||||
-(NSRect)titleRectForBounds:(NSRect)rect {
|
||||
return rect;
|
||||
}
|
||||
|
||||
-(NSRect)drawingRectForBounds:(NSRect)rect {
|
||||
return rect;
|
||||
}
|
||||
|
||||
-(void)drawInteriorWithFrame:(NSRect)frame inView:(NSView *)view {
|
||||
}
|
||||
|
||||
-(void)drawWithFrame:(NSRect)frame inView:(NSView *)view {
|
||||
|
||||
if([self type]==NSTextCellType){
|
||||
if([self isBezeled])
|
||||
NSDrawWhiteBezel(frame,frame);
|
||||
}
|
||||
|
||||
[self drawInteriorWithFrame:[self drawingRectForBounds:frame] inView:view];
|
||||
}
|
||||
|
||||
-(void)highlight:(BOOL)highlight withFrame:(NSRect)frame inView:(NSView *)view {
|
||||
if(_isHighlighted!=highlight){
|
||||
_isHighlighted=highlight;
|
||||
[self drawWithFrame:frame inView:view];
|
||||
}
|
||||
}
|
||||
|
||||
-(BOOL)startTrackingAt:(NSPoint)startPoint inView:(NSView *)view {
|
||||
return YES;
|
||||
}
|
||||
|
||||
-(BOOL)continueTracking:(NSPoint)lastPoint at:(NSPoint)currentPoint inView:(NSView *)view {
|
||||
return YES;
|
||||
}
|
||||
|
||||
-(void)stopTracking:(NSPoint)lastPoint at:(NSPoint)stopPoint inView:(NSView *)view mouseIsUp:(BOOL)flag {
|
||||
}
|
||||
|
||||
-(BOOL)trackMouse:(NSEvent *)event inRect:(NSRect)frame ofView:(NSView *)view untilMouseUp:(BOOL)untilMouseUp {
|
||||
NSPoint lastPoint;
|
||||
BOOL result=NO;
|
||||
|
||||
if(![self startTrackingAt:[event locationInWindow] inView:view])
|
||||
return NO;
|
||||
|
||||
[self drawWithFrame:frame inView:view];
|
||||
|
||||
do{
|
||||
NSPoint currentPoint;
|
||||
BOOL isWithinCellFrame;
|
||||
|
||||
lastPoint=[event locationInWindow];
|
||||
currentPoint=[view convertPoint:[event locationInWindow] fromView:nil];
|
||||
isWithinCellFrame=NSMouseInRect(currentPoint,frame,[view isFlipped]);
|
||||
|
||||
//NSLog(@"%@ in %@", NSStringFromPoint(currentPoint), NSStringFromRect(frame));
|
||||
if(untilMouseUp){
|
||||
if([event type]==NSLeftMouseUp){
|
||||
[self stopTracking:lastPoint at:[event locationInWindow] inView:view mouseIsUp:YES];
|
||||
result=YES;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if(isWithinCellFrame){
|
||||
if([event type]==NSLeftMouseUp){
|
||||
[self stopTracking:lastPoint at:[event locationInWindow] inView:view mouseIsUp:YES];
|
||||
result=YES;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
[self stopTracking:lastPoint at:[event locationInWindow] inView:view mouseIsUp:NO];
|
||||
result=NO;
|
||||
break;
|
||||
}
|
||||
|
||||
if(isWithinCellFrame) {
|
||||
if(![self continueTracking:lastPoint at:[event locationInWindow] inView:view])
|
||||
break;
|
||||
|
||||
if([self isContinuous])
|
||||
[(NSControl *)view sendAction:[(NSControl *)view action] to:[(NSControl *)view target]];
|
||||
}
|
||||
|
||||
[[view window] flushWindow];
|
||||
|
||||
event=[[view window] nextEventMatchingMask:NSLeftMouseUpMask|
|
||||
NSLeftMouseDraggedMask];
|
||||
|
||||
}while(YES);
|
||||
|
||||
[self drawWithFrame:frame inView:view];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
-(NSText *)setUpFieldEditorAttributes:(NSText *)editor {
|
||||
[editor setEditable:[self isEditable]];
|
||||
[editor setSelectable:[self isSelectable]];
|
||||
[editor setString:[self stringValue]];
|
||||
[editor setFont:[self font]];
|
||||
[editor setAlignment:[self alignment]];
|
||||
if([self respondsToSelector:@selector(drawsBackground)])
|
||||
[editor setDrawsBackground:(BOOL)(int)[self performSelector:@selector(drawsBackground)]];
|
||||
if([self respondsToSelector:@selector(backgroundColor)])
|
||||
[editor setBackgroundColor:[self performSelector:@selector(backgroundColor)]];
|
||||
|
||||
return editor;
|
||||
}
|
||||
|
||||
-(void)_setupFieldEditorWithFrame:(NSRect)frame controlView:(NSView *)view editor:(NSText *)editor delegate:delegate {
|
||||
/* There is some funkiness here where the editor is already in the control and it is moving to
|
||||
a different cell or the same cell is being edited after a makeFirstResponder
|
||||
This needs to be straightened out
|
||||
*/
|
||||
if([self isScrollable]){
|
||||
NSClipView *clipView;
|
||||
|
||||
if([[editor superview] isKindOfClass:[NSClipView class]]){
|
||||
clipView=[editor superview];
|
||||
[clipView setFrame:[self titleRectForBounds:frame]];
|
||||
}
|
||||
else {
|
||||
clipView=[[[NSClipView alloc] initWithFrame:[self titleRectForBounds:frame]] autorelease];
|
||||
[clipView setDocumentView:editor];
|
||||
[view addSubview:clipView];
|
||||
}
|
||||
|
||||
[clipView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
|
||||
[editor setAutoresizingMask:0];
|
||||
[editor setHorizontallyResizable:YES];
|
||||
[editor setVerticallyResizable:YES];
|
||||
[editor sizeToFit];
|
||||
[editor setNeedsDisplay:YES];
|
||||
}
|
||||
else {
|
||||
[editor setFrame:[self titleRectForBounds:frame]];
|
||||
[view addSubview:editor];
|
||||
}
|
||||
[[view window] makeFirstResponder:editor];
|
||||
[editor setDelegate:delegate];
|
||||
}
|
||||
|
||||
-(void)editWithFrame:(NSRect)frame inView:(NSView *)view editor:(NSText *)editor delegate:(id)delegate event:(NSEvent *)event {
|
||||
if(![self isEditable] && ![self isSelectable])
|
||||
return;
|
||||
|
||||
if(view == nil || editor == nil || [self font] == nil || _cellType != NSTextCellType)
|
||||
return;
|
||||
|
||||
[self _setupFieldEditorWithFrame:frame controlView:view editor:editor delegate:delegate];
|
||||
[editor mouseDown:event];
|
||||
}
|
||||
|
||||
-(void)selectWithFrame:(NSRect)frame inView:(NSView *)view editor:(NSText *)editor delegate:(id)delegate start:(int)location length:(int)length {
|
||||
if(![self isEditable] && ![self isSelectable])
|
||||
return;
|
||||
|
||||
if(view == nil || editor == nil || [self font] == nil || _cellType != NSTextCellType)
|
||||
return;
|
||||
|
||||
[self _setupFieldEditorWithFrame:frame controlView:view editor:editor delegate:delegate];
|
||||
[editor setSelectedRange:NSMakeRange(location,length)];
|
||||
}
|
||||
|
||||
-(void)endEditing:(NSText *)editor {
|
||||
[self setStringValue:[editor string]];
|
||||
}
|
||||
|
||||
-(void)resetCursorRect:(NSRect)rect inView:(NSView *)view {
|
||||
if(([self type]==NSTextCellType) && [self isEnabled]){
|
||||
if([self isEditable] || [self isSelectable]){
|
||||
NSRect titleRect=[self titleRectForBounds:rect];
|
||||
|
||||
titleRect=NSIntersectionRect(titleRect,[view visibleRect]);
|
||||
|
||||
if(!NSIsEmptyRect(titleRect))
|
||||
[view addCursorRect:titleRect cursor:[NSCursor IBeamCursor]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
30
AppKit/NSClipView.h
Executable file
30
AppKit/NSClipView.h
Executable file
@ -0,0 +1,30 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/NSView.h>
|
||||
|
||||
@class NSColor;
|
||||
|
||||
@interface NSClipView : NSView {
|
||||
NSColor *_backgroundColor;
|
||||
|
||||
NSView *_docView;
|
||||
NSRect _docRect;
|
||||
}
|
||||
|
||||
-(NSColor *)backgroundColor;
|
||||
-(id)documentView;
|
||||
-(NSRect)documentVisibleRect;
|
||||
|
||||
-(void)setBackgroundColor:(NSColor *)color;
|
||||
-(void)setDocumentView:(NSView *)view;
|
||||
|
||||
-(NSPoint)constrainScrollPoint:(NSPoint)point;
|
||||
-(void)scrollToPoint:(NSPoint)point;
|
||||
|
||||
@end
|
207
AppKit/NSClipView.m
Executable file
207
AppKit/NSClipView.m
Executable file
@ -0,0 +1,207 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/NSClipView.h>
|
||||
#import <AppKit/NSColor.h>
|
||||
#import <AppKit/NSGraphics.h>
|
||||
#import <AppKit/NSScrollView.h>
|
||||
#import <AppKit/NSEvent.h>
|
||||
#import <AppKit/NSNibKeyedUnarchiver.h>
|
||||
|
||||
@implementation NSClipView
|
||||
|
||||
-(void)encodeWithCoder:(NSCoder *)coder {
|
||||
NSUnimplementedMethod();
|
||||
}
|
||||
|
||||
-initWithCoder:(NSCoder *)coder {
|
||||
[super initWithCoder:coder];
|
||||
|
||||
if([coder isKindOfClass:[NSNibKeyedUnarchiver class]]){
|
||||
NSNibKeyedUnarchiver *keyed=(NSNibKeyedUnarchiver *)coder;
|
||||
|
||||
_backgroundColor=[[keyed decodeObjectForKey:@"NSBGColor"] retain];
|
||||
_docView=[[keyed decodeObjectForKey:@"NSDocView"] retain];
|
||||
|
||||
if(_docView!=nil)
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(viewFrameChanged:)
|
||||
name:NSViewFrameDidChangeNotification object:_docView];
|
||||
}
|
||||
else {
|
||||
[NSException raise:NSInvalidArgumentException format:@"-[%@ %s] is not implemented for coder %@",isa,SELNAME(_cmd),coder];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-initWithFrame:(NSRect)frame {
|
||||
[super initWithFrame:frame];
|
||||
_backgroundColor=[[NSColor controlBackgroundColor] retain];
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)dealloc {
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
[_backgroundColor release];
|
||||
[_docView release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
-(NSColor *)backgroundColor {
|
||||
return _backgroundColor;
|
||||
}
|
||||
|
||||
-(id)documentView {
|
||||
return _docView;
|
||||
}
|
||||
|
||||
-(NSRect)documentVisibleRect {
|
||||
return [self convertRect:[self bounds] toView:_docView];
|
||||
}
|
||||
|
||||
-(void)setBackgroundColor:(NSColor *)color {
|
||||
color=[color copy];
|
||||
[_backgroundColor release];
|
||||
_backgroundColor=color;
|
||||
}
|
||||
|
||||
-(void)setDocumentView:(NSView *)view {
|
||||
if(_docView!=nil){
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self
|
||||
name:NSViewFrameDidChangeNotification object:_docView];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self
|
||||
name:NSViewBoundsDidChangeNotification object:_docView];
|
||||
}
|
||||
|
||||
[_docView removeFromSuperview];
|
||||
|
||||
view=[view retain];
|
||||
[_docView release];
|
||||
_docView=view;
|
||||
|
||||
[self addSubview:view];
|
||||
|
||||
if(_docView!=nil){
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(viewFrameChanged:)
|
||||
name:NSViewFrameDidChangeNotification object:_docView];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(viewBoundsChanged:)
|
||||
name: NSViewBoundsDidChangeNotification object:_docView];
|
||||
}
|
||||
}
|
||||
|
||||
-(NSPoint)_scrollPoint {
|
||||
return [self bounds].origin;
|
||||
}
|
||||
|
||||
-(void)viewBoundsChanged:(NSNotification *)note {
|
||||
[self scrollToPoint:[self _scrollPoint]];
|
||||
}
|
||||
|
||||
-(void)viewFrameChanged:(NSNotification *)note {
|
||||
[self scrollToPoint:[self _scrollPoint]];
|
||||
}
|
||||
|
||||
-(NSPoint)constrainScrollPoint:(NSPoint)point {
|
||||
NSRect bounds=[self bounds];
|
||||
NSRect docFrame=[[self documentView] frame];
|
||||
|
||||
if(point.y<docFrame.origin.y)
|
||||
point.y=docFrame.origin.y;
|
||||
|
||||
if(point.x<docFrame.origin.x)
|
||||
point.x=docFrame.origin.x;
|
||||
|
||||
if(docFrame.size.height<bounds.size.height)
|
||||
point.y=docFrame.origin.y;
|
||||
else if(point.y+bounds.size.height>NSMaxY(docFrame))
|
||||
point.y=NSMaxY(docFrame)-bounds.size.height;
|
||||
|
||||
if(docFrame.size.width<bounds.size.width)
|
||||
point.x=docFrame.origin.x;
|
||||
else if(point.x+bounds.size.width>NSMaxX(docFrame))
|
||||
point.x=NSMaxX(docFrame)-bounds.size.width;
|
||||
|
||||
return point;
|
||||
}
|
||||
|
||||
-(BOOL)isOpaque {
|
||||
return YES;
|
||||
}
|
||||
|
||||
-(BOOL)isFlipped {
|
||||
return [_docView isFlipped];
|
||||
}
|
||||
|
||||
-(void)drawRect:(NSRect)rect {
|
||||
if([_docView isOpaque]){
|
||||
NSRect bounds=[self bounds];
|
||||
NSRect frame=[_docView frame];
|
||||
NSRect intersection=NSIntersectionRect(bounds,frame);
|
||||
|
||||
if(NSEqualRects(bounds,intersection))
|
||||
return;
|
||||
}
|
||||
[_backgroundColor set];
|
||||
NSRectFill(rect);
|
||||
}
|
||||
|
||||
-(void)scrollToPoint:(NSPoint)point {
|
||||
NSPoint original=[self bounds].origin;
|
||||
|
||||
point=[self constrainScrollPoint:point];
|
||||
[self setBoundsOrigin:point];
|
||||
[self setNeedsDisplay:YES];
|
||||
|
||||
if([[self superview] isKindOfClass:[NSScrollView class]])
|
||||
[[self superview] reflectScrolledClipView:self];
|
||||
}
|
||||
|
||||
-(BOOL)autoscroll:(NSEvent *)event {
|
||||
NSRect bounds=[self bounds];
|
||||
NSPoint point=[self convertPoint:[event locationInWindow] fromView:nil];
|
||||
int deltax=0,deltay=0;
|
||||
NSView *superview=[self superview];
|
||||
|
||||
if(NSMouseInRect(point,bounds,[self isFlipped]))
|
||||
return NO;
|
||||
|
||||
if(![superview isKindOfClass:[NSScrollView class]] ||
|
||||
[(NSScrollView *)[self superview] hasVerticalScroller]){
|
||||
if(point.y<NSMinY(bounds))
|
||||
deltay=NSMinY(bounds)-point.y;
|
||||
else if(point.y>NSMaxY(bounds))
|
||||
deltay=NSMaxY(bounds)-point.y;
|
||||
if(deltay<-bounds.size.height)
|
||||
deltay=-bounds.size.height;
|
||||
if(deltay>bounds.size.height)
|
||||
deltay=bounds.size.height;
|
||||
}
|
||||
if(![superview isKindOfClass:[NSScrollView class]] ||
|
||||
[(NSScrollView *)[self superview] hasHorizontalScroller]){
|
||||
if(point.x<NSMinX(bounds))
|
||||
deltax=NSMinX(bounds)-point.x;
|
||||
else if(point.x>NSMaxX(bounds))
|
||||
deltax=NSMaxX(bounds)-point.x;
|
||||
if(deltax<-bounds.size.width)
|
||||
deltax=-bounds.size.width;
|
||||
if(deltax>bounds.size.width)
|
||||
deltax=bounds.size.width;
|
||||
}
|
||||
|
||||
bounds.origin.y-=deltay;
|
||||
bounds.origin.x-=deltax;
|
||||
|
||||
[self scrollToPoint:bounds.origin];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
114
AppKit/NSColor.subproj/NSColor.h
Executable file
114
AppKit/NSColor.subproj/NSColor.h
Executable file
@ -0,0 +1,114 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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 <Foundation/Foundation.h>
|
||||
#import <AppKit/AppKitExport.h>
|
||||
|
||||
@class NSPasteboard;
|
||||
|
||||
@interface NSColor : NSObject <NSCopying>
|
||||
|
||||
+(NSColor *)highlightColor;
|
||||
+(NSColor *)shadowColor;
|
||||
+(NSColor *)gridColor;
|
||||
|
||||
+(NSColor *)controlColor;
|
||||
+(NSColor *)selectedControlColor;
|
||||
+(NSColor *)controlTextColor;
|
||||
+(NSColor *)selectedControlTextColor;
|
||||
+(NSColor *)disabledControlTextColor;
|
||||
+(NSColor *)controlBackgroundColor;
|
||||
+(NSColor *)controlDarkShadowColor;
|
||||
+(NSColor *)controlHighlightColor;
|
||||
+(NSColor *)controlLightHighlightColor;
|
||||
+(NSColor *)controlShadowColor;
|
||||
|
||||
+(NSColor *)textColor;
|
||||
+(NSColor *)textBackgroundColor;
|
||||
+(NSColor *)selectedTextColor;
|
||||
+(NSColor *)selectedTextBackgroundColor;
|
||||
|
||||
+(NSColor *)headerColor;
|
||||
+(NSColor *)headerTextColor;
|
||||
|
||||
+(NSColor *)scrollBarColor;
|
||||
+(NSColor *)knobColor;
|
||||
+(NSColor *)selectedKnobColor;
|
||||
|
||||
+(NSColor *)windowBackgroundColor;
|
||||
|
||||
// private
|
||||
+(NSColor *)menuBackgroundColor;
|
||||
+(NSColor *)menuItemTextColor;
|
||||
|
||||
+(NSColor *)clearColor;
|
||||
|
||||
+(NSColor *)blackColor;
|
||||
+(NSColor *)blueColor;
|
||||
+(NSColor *)brownColor;
|
||||
+(NSColor *)cyanColor;
|
||||
+(NSColor *)darkGrayColor;
|
||||
+(NSColor *)grayColor;
|
||||
+(NSColor *)greenColor;
|
||||
+(NSColor *)lightGrayColor;
|
||||
+(NSColor *)magentaColor;
|
||||
+(NSColor *)orangeColor;
|
||||
+(NSColor *)purpleColor;
|
||||
+(NSColor *)redColor;
|
||||
+(NSColor *)whiteColor;
|
||||
+(NSColor *)yellowColor;
|
||||
|
||||
+(NSColor *)colorWithDeviceWhite:(float)white alpha:(float)alpha;
|
||||
+(NSColor *)colorWithDeviceRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha;
|
||||
+(NSColor *)colorWithDeviceHue:(float)hue saturation:(float)saturation brightness:(float)brightness alpha:(float)alpha;
|
||||
+(NSColor *)colorWithDeviceCyan:(float)cyan magenta:(float)magenta yellow:(float)yellow black:(float)black alpha:(float)alpha;
|
||||
|
||||
+(NSColor *)colorWithCalibratedWhite:(float)white alpha:(float)alpha;
|
||||
+(NSColor *)colorWithCalibratedRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha;
|
||||
+(NSColor *)colorWithCalibratedHue:(float)hue saturation:(float)saturation brightness:(float)brightness alpha:(float)alpha;
|
||||
|
||||
+(NSColor *)colorWithCatalogName:(NSString *)catalogName colorName:(NSString *)colorName;
|
||||
|
||||
+(NSColor *)colorFromPasteboard:(NSPasteboard *)pasteboard;
|
||||
|
||||
-(NSString *)colorSpaceName;
|
||||
|
||||
-(void)getWhite:(float *)white alpha:(float *)alpha;
|
||||
-(void)getRed:(float *)red green:(float *)green blue:(float *)blue alpha:(float *)alpha;
|
||||
-(void)getHue:(float *)hue saturation:(float *)saturation brightness:(float *)brightness alpha:(float *)alpha;
|
||||
-(void)getCyan:(float *)cyan magenta:(float *)magenta yellow:(float *)yellow black:(float *)black alpha:(float *)alpha;
|
||||
|
||||
-(float)whiteComponent;
|
||||
|
||||
-(float)redComponent;
|
||||
-(float)greenComponent;
|
||||
-(float)blueComponent;
|
||||
|
||||
-(float)hueComponent;
|
||||
-(float)saturationComponent;
|
||||
-(float)brightnessComponent;
|
||||
|
||||
-(float)cyanComponent;
|
||||
-(float)magentaComponent;
|
||||
-(float)yellowComponent;
|
||||
-(float)blackComponent;
|
||||
|
||||
-(float)alphaComponent;
|
||||
|
||||
-(NSColor *)colorUsingColorSpaceName:(NSString *)colorSpace;
|
||||
-(NSColor *)colorUsingColorSpaceName:(NSString *)colorSpace device:(NSDictionary *)device;
|
||||
|
||||
-(NSColor *)blendedColorWithFraction:(float)fraction ofColor:(NSColor *)color;
|
||||
|
||||
-(void)set;
|
||||
|
||||
-(void)drawSwatchInRect:(NSRect)rect;
|
||||
|
||||
-(void)writeToPasteboard:(NSPasteboard *)pasteboard;
|
||||
|
||||
@end
|
547
AppKit/NSColor.subproj/NSColor.m
Executable file
547
AppKit/NSColor.subproj/NSColor.m
Executable file
@ -0,0 +1,547 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/NSColor.h>
|
||||
#import <AppKit/NSColor_whiteCalibrated.h>
|
||||
#import <AppKit/NSColor_rgbCalibrated.h>
|
||||
#import <AppKit/NSColor_whiteDevice.h>
|
||||
#import <AppKit/NSColor_rgbDevice.h>
|
||||
#import <AppKit/NSColor_cmykDevice.h>
|
||||
#import <AppKit/NSColor_catalog.h>
|
||||
|
||||
#import <AppKit/NSGraphics.h>
|
||||
#import <AppKit/NSGraphicsContext.h>
|
||||
|
||||
#import <AppKit/NSPasteboard.h>
|
||||
#import <AppKit/NSNibKeyedUnarchiver.h>
|
||||
|
||||
@implementation NSColor
|
||||
|
||||
-(void)encodeWithCoder:(NSCoder *)coder {
|
||||
NSUnimplementedMethod();
|
||||
}
|
||||
|
||||
-initWithCoder:(NSCoder *)coder {
|
||||
if([coder isKindOfClass:[NSNibKeyedUnarchiver class]]){
|
||||
NSNibKeyedUnarchiver *keyed=(NSNibKeyedUnarchiver *)coder;
|
||||
int colorSpace=[keyed decodeIntForKey:@"NSColorSpace"];
|
||||
NSColor *result;
|
||||
|
||||
switch(colorSpace){
|
||||
|
||||
case 1:{
|
||||
// NSComponents data
|
||||
// NSCustomColorSpace NSColorSpace
|
||||
unsigned length;
|
||||
const char *rgb=[keyed decodeBytesForKey:@"NSRGB" returnedLength:&length];
|
||||
NSString *string=[NSString stringWithCString:rgb length:length];
|
||||
NSArray *components=[string componentsSeparatedByString:@" "];
|
||||
float values[4]={0,0,0,1};
|
||||
int i,count=[components count];
|
||||
|
||||
for(i=0;i<count && i<4;i++)
|
||||
values[i]=[[components objectAtIndex:i] floatValue];
|
||||
|
||||
result=[NSColor colorWithCalibratedRed:values[0] green:values[1] blue:values[2] alpha:values[3]];
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:{
|
||||
unsigned length;
|
||||
const char *rgb=[keyed decodeBytesForKey:@"NSRGB" returnedLength:&length];
|
||||
NSString *string=[NSString stringWithCString:rgb length:length];
|
||||
NSArray *components=[string componentsSeparatedByString:@" "];
|
||||
float values[4]={0,0,0,1};
|
||||
int i,count=[components count];
|
||||
|
||||
for(i=0;i<count && i<4;i++)
|
||||
values[i]=[[components objectAtIndex:i] floatValue];
|
||||
|
||||
result=[NSColor colorWithDeviceRed:values[0] green:values[1] blue:values[2] alpha:values[3]];
|
||||
}
|
||||
break;
|
||||
|
||||
case 3:{
|
||||
unsigned length;
|
||||
const char *white=[keyed decodeBytesForKey:@"NSWhite" returnedLength:&length];
|
||||
NSString *string=[NSString stringWithCString:white length:length-1];
|
||||
NSArray *components=[string componentsSeparatedByString:@" "];
|
||||
float values[2]={0,1};
|
||||
int i,count=[components count];
|
||||
|
||||
for(i=0;i<count && i<2;i++)
|
||||
values[i]=[[components objectAtIndex:i] floatValue];
|
||||
|
||||
result=[NSColor colorWithCalibratedWhite:values[0] alpha:values[1]];
|
||||
}
|
||||
break;
|
||||
|
||||
case 4:{
|
||||
unsigned length;
|
||||
const char *white=[keyed decodeBytesForKey:@"NSWhite" returnedLength:&length];
|
||||
NSString *string=[NSString stringWithCString:white length:length];
|
||||
NSArray *components=[string componentsSeparatedByString:@" "];
|
||||
float values[2]={0,1};
|
||||
int i,count=[components count];
|
||||
|
||||
for(i=0;i<count && i<2;i++)
|
||||
values[i]=[[components objectAtIndex:i] floatValue];
|
||||
|
||||
result=[NSColor colorWithDeviceWhite:values[0] alpha:values[1]];
|
||||
}
|
||||
break;
|
||||
|
||||
case 5:{
|
||||
// NSComponents data
|
||||
// NSCustomColorSpace NSColorSpace
|
||||
unsigned length;
|
||||
const char *cmyk=[keyed decodeBytesForKey:@"NSCMYK" returnedLength:&length];
|
||||
NSString *string=[NSString stringWithCString:cmyk length:length];
|
||||
NSArray *components=[string componentsSeparatedByString:@" "];
|
||||
float values[5]={0,0,0,0,1};
|
||||
int i,count=[components count];
|
||||
|
||||
for(i=0;i<count && i<5;i++)
|
||||
values[i]=[[components objectAtIndex:i] floatValue];
|
||||
|
||||
result=[NSColor colorWithDeviceCyan:values[0] magenta:values[1] yellow:values[2] black:values[3] alpha:values[4]];
|
||||
}
|
||||
break;
|
||||
|
||||
case 6:{
|
||||
NSString *catalogName=[keyed decodeObjectForKey:@"NSCatalogName"];
|
||||
NSString *colorName=[keyed decodeObjectForKey:@"NSColorName"];
|
||||
NSColor *color=[keyed decodeObjectForKey:@"NSColor"]; // backup ?
|
||||
|
||||
if((result=[NSColor colorWithCatalogName:catalogName colorName:colorName])==nil)
|
||||
result=color;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
NSLog(@"-[%@ %s] unknown color space %d",isa,SELNAME(_cmd),colorSpace);
|
||||
result=[NSColor blackColor];
|
||||
break;
|
||||
}
|
||||
|
||||
return [result retain];
|
||||
}
|
||||
else {
|
||||
NSString *space=[coder decodeObject];
|
||||
|
||||
[self dealloc];
|
||||
|
||||
if([space isEqualToString:@"NSDeviceCMYKColorSpace"]){
|
||||
float c,m,y,k,a;
|
||||
|
||||
[coder decodeValuesOfObjCTypes:"fffff",&c,&m,&y,&k,&a];
|
||||
|
||||
return [[NSColor colorWithDeviceCyan:c magenta:m yellow:y black:k alpha:a] retain];
|
||||
}
|
||||
else if([space isEqualToString:@"NSDeviceWhiteColorSpace"]){
|
||||
float w,a;
|
||||
|
||||
[coder decodeValuesOfObjCTypes:"ff",&w,&a];
|
||||
|
||||
return [[NSColor colorWithDeviceWhite:w alpha:a] retain];
|
||||
}
|
||||
else if([space isEqualToString:@"NSCalibratedWhiteColorSpace"]){
|
||||
float w,a;
|
||||
|
||||
[coder decodeValuesOfObjCTypes:"ff",&w,&a];
|
||||
|
||||
return [[NSColor colorWithCalibratedWhite:w alpha:a] retain];
|
||||
}
|
||||
else if([space isEqualToString:@"NSDeviceRGBColorSpace"]){
|
||||
float r,g,b,a;
|
||||
|
||||
[coder decodeValuesOfObjCTypes:"ffff",&r,&g,&b,&a];
|
||||
|
||||
return [[NSColor colorWithDeviceRed:r green:g blue:b alpha:a] retain];
|
||||
}
|
||||
else if([space isEqualToString:@"NSCalibratedRGBColorSpace"]){
|
||||
float r,g,b,a;
|
||||
|
||||
[coder decodeValuesOfObjCTypes:"ffff",&r,&g,&b,&a];
|
||||
|
||||
return [[NSColor colorWithCalibratedRed:r green:g blue:b alpha:a] retain];
|
||||
}
|
||||
else if([space isEqualToString:@"NSNamedColorSpace"]){
|
||||
NSString *catalog=[coder decodeObject];
|
||||
NSString *color=[coder decodeObject];
|
||||
|
||||
return [[NSColor colorWithCatalogName:catalog colorName:color] retain];
|
||||
}
|
||||
else {
|
||||
[NSException raise:@"UnknownColor" format:@"Unknown color space %@",space];
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-copyWithZone:(NSZone *)zone {
|
||||
return [self retain];
|
||||
}
|
||||
|
||||
+(NSColor *)highlightColor {
|
||||
return [NSColor colorWithCatalogName:@"System" colorName:@"highlightColor"];
|
||||
}
|
||||
|
||||
+(NSColor *)shadowColor {
|
||||
return [NSColor colorWithCatalogName:@"System" colorName:@"shadowColor"];
|
||||
}
|
||||
|
||||
+(NSColor *)gridColor {
|
||||
return [NSColor colorWithCatalogName:@"System" colorName:@"gridColor"];
|
||||
}
|
||||
|
||||
+(NSColor *)controlColor {
|
||||
return [NSColor colorWithCatalogName:@"System" colorName:@"controlColor"];
|
||||
}
|
||||
|
||||
+(NSColor *)selectedControlColor {
|
||||
return [NSColor colorWithCatalogName:@"System" colorName:@"selectedControlColor"];
|
||||
}
|
||||
|
||||
+(NSColor *)controlTextColor {
|
||||
return [NSColor colorWithCatalogName:@"System" colorName:@"controlTextColor"];
|
||||
}
|
||||
|
||||
+(NSColor *)selectedControlTextColor {
|
||||
return [NSColor colorWithCatalogName:@"System" colorName:@"selectedControlTextColor"];
|
||||
}
|
||||
|
||||
+(NSColor *)disabledControlTextColor {
|
||||
return [NSColor colorWithCatalogName:@"System" colorName:@"disabledControlTextColor"];
|
||||
}
|
||||
|
||||
+(NSColor *)controlBackgroundColor {
|
||||
return [NSColor colorWithCatalogName:@"System" colorName:@"controlBackgroundColor"];
|
||||
}
|
||||
|
||||
+(NSColor *)controlDarkShadowColor {
|
||||
return [NSColor colorWithCatalogName:@"System" colorName:@"controlDarkShadowColor"];
|
||||
}
|
||||
|
||||
+(NSColor *)controlHighlightColor {
|
||||
return [NSColor colorWithCatalogName:@"System" colorName:@"controlHighlightColor"];
|
||||
}
|
||||
|
||||
+(NSColor *)controlLightHighlightColor {
|
||||
return [NSColor colorWithCatalogName:@"System" colorName:@"controlLightHighlightColor"];
|
||||
}
|
||||
|
||||
+(NSColor *)controlShadowColor {
|
||||
return [NSColor colorWithCatalogName:@"System" colorName:@"controlShadowColor"];
|
||||
}
|
||||
|
||||
+(NSColor *)textColor {
|
||||
return [NSColor colorWithCatalogName:@"System" colorName:@"textColor"];
|
||||
}
|
||||
|
||||
+(NSColor *)textBackgroundColor {
|
||||
return [NSColor colorWithCatalogName:@"System" colorName:@"textBackgroundColor"];
|
||||
}
|
||||
|
||||
+(NSColor *)selectedTextColor {
|
||||
return [NSColor colorWithCatalogName:@"System" colorName:@"selectedTextColor"];
|
||||
}
|
||||
|
||||
+(NSColor *)selectedTextBackgroundColor {
|
||||
return [NSColor colorWithCatalogName:@"System" colorName:@"selectedTextBackgroundColor"];
|
||||
}
|
||||
|
||||
+(NSColor *)headerColor {
|
||||
return [NSColor colorWithCatalogName:@"System" colorName:@"headerColor"];
|
||||
}
|
||||
|
||||
+(NSColor *)headerTextColor {
|
||||
return [NSColor colorWithCatalogName:@"System" colorName:@"headerTextColor"];
|
||||
}
|
||||
|
||||
+(NSColor *)scrollBarColor {
|
||||
return [NSColor colorWithCatalogName:@"System" colorName:@"scrollBarColor"];
|
||||
}
|
||||
|
||||
+(NSColor *)knobColor {
|
||||
return [NSColor colorWithCatalogName:@"System" colorName:@"knobColor"];
|
||||
}
|
||||
|
||||
+(NSColor *)selectedKnobColor {
|
||||
return [NSColor colorWithCatalogName:@"System" colorName:@"selectedKnobColor"];
|
||||
}
|
||||
|
||||
+(NSColor *)windowBackgroundColor {
|
||||
return [NSColor controlColor];
|
||||
}
|
||||
|
||||
+(NSColor *)menuBackgroundColor {
|
||||
return [NSColor colorWithCatalogName:@"System" colorName:@"menuBackgroundColor"];
|
||||
}
|
||||
|
||||
+(NSColor *)menuItemTextColor {
|
||||
return [NSColor colorWithCatalogName:@"System" colorName:@"menuItemTextColor"];
|
||||
}
|
||||
|
||||
+(NSColor *)clearColor {
|
||||
return [NSColor colorWithCalibratedRed:0 green:0 blue:0 alpha:0];
|
||||
}
|
||||
|
||||
+(NSColor *)blackColor {
|
||||
return [NSColor_whiteCalibrated blackColor];
|
||||
}
|
||||
|
||||
+(NSColor *)blueColor {
|
||||
return [NSColor colorWithCalibratedRed:0.0 green:0.0 blue:1.0 alpha:1.0];
|
||||
}
|
||||
|
||||
+(NSColor *)brownColor {
|
||||
return [NSColor colorWithCalibratedRed:0.6 green:0.4 blue:0.2 alpha:1.0];
|
||||
}
|
||||
|
||||
+(NSColor *)cyanColor {
|
||||
return [NSColor colorWithCalibratedRed:0.0 green:1.0 blue:1.0 alpha:1.0];
|
||||
}
|
||||
|
||||
+(NSColor *)darkGrayColor {
|
||||
return [NSColor_whiteCalibrated darkGrayColor];
|
||||
}
|
||||
|
||||
+(NSColor *)grayColor {
|
||||
return [NSColor_whiteCalibrated grayColor];
|
||||
}
|
||||
|
||||
+(NSColor *)greenColor {
|
||||
return [NSColor colorWithCalibratedRed:0.0 green:1.0 blue:0.0 alpha:1.0];
|
||||
}
|
||||
|
||||
+(NSColor *)lightGrayColor {
|
||||
return [NSColor_whiteCalibrated lightGrayColor];
|
||||
}
|
||||
|
||||
+(NSColor *)magentaColor {
|
||||
return [NSColor colorWithCalibratedRed:1.0 green:0.0 blue:1.0 alpha:1.0];
|
||||
}
|
||||
|
||||
+(NSColor *)orangeColor {
|
||||
return [NSColor colorWithCalibratedRed:1.0 green:0.5 blue:0.0 alpha:1.0];
|
||||
}
|
||||
|
||||
+(NSColor *)purpleColor {
|
||||
return [NSColor colorWithCalibratedRed:0.5 green:0.0 blue:0.5 alpha:1.0];
|
||||
}
|
||||
|
||||
+(NSColor *)redColor {
|
||||
return [NSColor colorWithCalibratedRed:1.0 green:0.0 blue:0.0 alpha:1.0];
|
||||
}
|
||||
|
||||
+(NSColor *)whiteColor {
|
||||
return [NSColor_whiteCalibrated whiteColor];
|
||||
}
|
||||
|
||||
+(NSColor *)yellowColor {
|
||||
return [NSColor colorWithCalibratedRed:1.0 green:1.0 blue:0.0 alpha:1.0];
|
||||
}
|
||||
|
||||
+(NSColor *)colorWithDeviceWhite:(float)white alpha:(float)alpha {
|
||||
return [NSColor_whiteDevice colorWithGray:white alpha:alpha];
|
||||
}
|
||||
|
||||
+(NSColor *)colorWithDeviceRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha {
|
||||
return [NSColor_rgbDevice colorWithRed:red green:green blue:blue alpha:alpha];
|
||||
}
|
||||
|
||||
+(NSColor *)colorWithDeviceHue:(float)hue saturation:(float)saturation brightness:(float)brightness alpha:(float)alpha {
|
||||
return [NSColor_rgbDevice colorWithHue:hue saturation:saturation brightness:brightness alpha:alpha];
|
||||
}
|
||||
|
||||
+(NSColor *)colorWithDeviceCyan:(float)cyan magenta:(float)magenta yellow:(float)yellow black:(float)black alpha:(float)alpha {
|
||||
return [NSColor_cmykDevice colorWithCyan:cyan magenta:magenta yellow:yellow black:black alpha:alpha];
|
||||
}
|
||||
|
||||
+(NSColor *)colorWithCalibratedWhite:(float)white alpha:(float)alpha {
|
||||
return [NSColor_whiteCalibrated colorWithGray:white alpha:alpha];
|
||||
}
|
||||
|
||||
+(NSColor *)colorWithCalibratedRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha {
|
||||
return [NSColor_rgbCalibrated colorWithRed:red green:green blue:blue alpha:alpha];
|
||||
}
|
||||
|
||||
+(NSColor *)colorWithCalibratedHue:(float)hue saturation:(float)saturation brightness:(float)brightness alpha:(float)alpha {
|
||||
return [NSColor_rgbCalibrated colorWithHue:hue saturation:saturation brightness:brightness alpha:alpha];
|
||||
}
|
||||
|
||||
+(NSColor *)colorWithCatalogName:(NSString *)catalogName colorName:(NSString *)colorName {
|
||||
return [NSColor_catalog colorWithCatalogName:catalogName colorName:colorName];
|
||||
}
|
||||
|
||||
+(NSColor *)colorFromPasteboard:(NSPasteboard *)pasteboard {
|
||||
NSData *data=[pasteboard dataForType:NSColorPboardType];
|
||||
|
||||
return [NSUnarchiver unarchiveObjectWithData:data];
|
||||
}
|
||||
|
||||
-(NSString *)colorSpaceName {
|
||||
NSInvalidAbstractInvocation();
|
||||
return nil;
|
||||
}
|
||||
|
||||
-(void)getWhite:(float *)white alpha:(float *)alpha {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-(void)getRed:(float *)red green:(float *)green blue:(float *)blue alpha:(float *)alpha {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-(void)getHue:(float *)hue saturation:(float *)saturation brightness:(float *)brightness alpha:(float *)alpha {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-(void)getCyan:(float *)cyan magenta:(float *)magenta yellow:(float *)yellow black:(float *)black alpha:(float *)alpha {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-(float)whiteComponent {
|
||||
float white, alpha;
|
||||
|
||||
[self getWhite:&white alpha:&alpha];
|
||||
return white;
|
||||
}
|
||||
|
||||
-(float)redComponent {
|
||||
float red,green,blue,alpha;
|
||||
|
||||
[self getRed:&red green:&green blue:&blue alpha:&alpha];
|
||||
|
||||
return red;
|
||||
}
|
||||
|
||||
-(float)greenComponent {
|
||||
float red,green,blue,alpha;
|
||||
|
||||
[self getRed:&red green:&green blue:&blue alpha:&alpha];
|
||||
|
||||
return green;
|
||||
}
|
||||
|
||||
-(float)blueComponent {
|
||||
float red,green,blue,alpha;
|
||||
|
||||
[self getRed:&red green:&green blue:&blue alpha:&alpha];
|
||||
|
||||
return blue;
|
||||
}
|
||||
|
||||
-(float)hueComponent {
|
||||
float hue,saturation,brightness,alpha;
|
||||
|
||||
[self getHue:&hue saturation:&saturation brightness:&brightness alpha:&alpha];
|
||||
|
||||
return hue;
|
||||
}
|
||||
|
||||
-(float)saturationComponent {
|
||||
float hue,saturation,brightness,alpha;
|
||||
|
||||
[self getHue:&hue saturation:&saturation brightness:&brightness alpha:&alpha];
|
||||
|
||||
return saturation;
|
||||
}
|
||||
|
||||
-(float)brightnessComponent {
|
||||
float hue,saturation,brightness,alpha;
|
||||
|
||||
[self getHue:&hue saturation:&saturation brightness:&brightness alpha:&alpha];
|
||||
|
||||
return brightness;
|
||||
}
|
||||
|
||||
-(float)cyanComponent {
|
||||
float cyan, magenta, yellow, black, alpha;
|
||||
|
||||
[self getCyan:&cyan magenta:&magenta yellow:&yellow black:&black alpha:&alpha];
|
||||
return cyan;
|
||||
}
|
||||
|
||||
-(float)magentaComponent {
|
||||
float cyan, magenta, yellow, black, alpha;
|
||||
|
||||
[self getCyan:&cyan magenta:&magenta yellow:&yellow black:&black alpha:&alpha];
|
||||
return magenta;
|
||||
}
|
||||
|
||||
-(float)yellowComponent {
|
||||
float cyan, magenta, yellow, black, alpha;
|
||||
|
||||
[self getCyan:&cyan magenta:&magenta yellow:&yellow black:&black alpha:&alpha];
|
||||
return yellow;
|
||||
}
|
||||
|
||||
-(float)blackComponent {
|
||||
float cyan, magenta, yellow, black, alpha;
|
||||
|
||||
[self getCyan:&cyan magenta:&magenta yellow:&yellow black:&black alpha:&alpha];
|
||||
return black;
|
||||
}
|
||||
|
||||
-(float)alphaComponent {
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
-(NSColor *)colorUsingColorSpaceName:(NSString *)colorSpace {
|
||||
return [self colorUsingColorSpaceName:colorSpace device:nil];
|
||||
}
|
||||
|
||||
-(NSColor *)colorUsingColorSpaceName:(NSString *)colorSpace device:(NSDictionary *)device {
|
||||
if([[self colorSpaceName] isEqualToString:colorSpace])
|
||||
return self;
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
-(NSColor *)blendedColorWithFraction:(float)fraction ofColor:(NSColor *)color {
|
||||
NSColor *primary=[color colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
|
||||
NSColor *secondary=[self colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
|
||||
|
||||
if(primary==nil || secondary==nil)
|
||||
return nil;
|
||||
else {
|
||||
float pr,pg,pb,pa;
|
||||
float sr,sg,sb,sa;
|
||||
float rr,rg,rb,ra;
|
||||
|
||||
[primary getRed:&pr green:&pg blue:&pb alpha:&pa];
|
||||
[secondary getRed:&sr green:&sg blue:&sb alpha:&sa];
|
||||
|
||||
rr=pr*fraction+sr*(1-fraction);
|
||||
rg=pg*fraction+sg*(1-fraction);
|
||||
rb=pb*fraction+sb*(1-fraction);
|
||||
ra=pa*fraction+sa*(1-fraction);
|
||||
|
||||
return [NSColor colorWithCalibratedRed:rr green:rg blue:rb alpha:ra];
|
||||
}
|
||||
}
|
||||
|
||||
-(void)set {
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
-(void)drawSwatchInRect:(NSRect)rect {
|
||||
[self set];
|
||||
NSRectFill(rect);
|
||||
}
|
||||
|
||||
-(void)writeToPasteboard:(NSPasteboard *)pasteboard {
|
||||
NSData *data=[NSArchiver archivedDataWithRootObject:self];
|
||||
|
||||
[pasteboard setData:data forType:NSColorPboardType];
|
||||
}
|
||||
|
||||
@end
|
18
AppKit/NSColor.subproj/NSColor_catalog.h
Executable file
18
AppKit/NSColor.subproj/NSColor_catalog.h
Executable file
@ -0,0 +1,18 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/NSColor.h>
|
||||
|
||||
@interface NSColor_catalog : NSColor {
|
||||
NSString *_catalogName;
|
||||
NSString *_colorName;
|
||||
}
|
||||
|
||||
+(NSColor *)colorWithCatalogName:(NSString *)catalogName colorName:(NSString *)colorName;
|
||||
|
||||
@end
|
82
AppKit/NSColor.subproj/NSColor_catalog.m
Executable file
82
AppKit/NSColor.subproj/NSColor_catalog.m
Executable file
@ -0,0 +1,82 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/NSColor_catalog.h>
|
||||
#import <AppKit/NSGraphics.h>
|
||||
#import <AppKit/NSDisplay.h>
|
||||
|
||||
@implementation NSColor_catalog
|
||||
|
||||
-initWithCatalogName:(NSString *)catalogName colorName:(NSString *)colorName {
|
||||
_catalogName=[catalogName copy];
|
||||
_colorName=[colorName copy];
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)dealloc {
|
||||
[_colorName release];
|
||||
[_catalogName release];
|
||||
NSDeallocateObject(self);
|
||||
}
|
||||
|
||||
-(void)encodeWithCoder:(NSCoder *)coder {
|
||||
[coder encodeObject:[self colorSpaceName]];
|
||||
[coder encodeObject:_catalogName];
|
||||
[coder encodeObject:_colorName];
|
||||
}
|
||||
|
||||
-(BOOL)isEqual:otherObject {
|
||||
if(self==otherObject)
|
||||
return YES;
|
||||
|
||||
if([otherObject isKindOfClass:[self class]]){
|
||||
NSColor_catalog *other=otherObject;
|
||||
|
||||
return ([_catalogName isEqualToString:other->_catalogName] && [_colorName isEqualToString:other-> _colorName]);
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (NSString *)description
|
||||
{
|
||||
return [NSString stringWithFormat:@"<%@ catalogName: %@ colorName: %@>",
|
||||
[[self class] description], _catalogName, _colorName];
|
||||
}
|
||||
|
||||
+(NSColor *)colorWithCatalogName:(NSString *)catalogName colorName:(NSString *)colorName {
|
||||
return [[[self alloc] initWithCatalogName:catalogName colorName:colorName] autorelease];
|
||||
}
|
||||
|
||||
-(NSString *)colorSpaceName {
|
||||
return NSNamedColorSpace;
|
||||
}
|
||||
|
||||
-(NSColor *)colorUsingColorSpaceName:(NSString *)colorSpace device:(NSDictionary *)device {
|
||||
NSColor *result;
|
||||
|
||||
if ([colorSpace isEqualToString:[self colorSpaceName]])
|
||||
return self;
|
||||
|
||||
result=[[[NSDisplay currentDisplay] colorWithName:_colorName] colorUsingColorSpaceName:colorSpace device:device];
|
||||
if(result==nil)
|
||||
NSLog(@"result ==nil %@ %@",_colorName,colorSpace);
|
||||
return result;
|
||||
}
|
||||
|
||||
-(void)set {
|
||||
NSColor *color=[[NSDisplay currentDisplay] colorWithName:_colorName];
|
||||
|
||||
if(color==nil)
|
||||
[NSException raise:@"NSUnknownColor" format:@"Unknown color %@ in catalog %@",_colorName,_catalogName];
|
||||
|
||||
[color set];
|
||||
}
|
||||
|
||||
@end
|
19
AppKit/NSColor.subproj/NSColor_cmykDevice.h
Executable file
19
AppKit/NSColor.subproj/NSColor_cmykDevice.h
Executable file
@ -0,0 +1,19 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/NSColor.h>
|
||||
|
||||
@interface NSColor_cmykDevice : NSColor {
|
||||
float _cyan,_magenta,_yellow,_black,_alpha;
|
||||
}
|
||||
|
||||
-initWithCyan:(float)cyan magenta:(float)magenta yellow:(float)yellow black:(float)black alpha:(float)alpha;
|
||||
|
||||
+(NSColor *)colorWithCyan:(float)cyan magenta:(float)magenta yellow:(float)yellow black:(float)black alpha:(float)alpha;
|
||||
|
||||
@end
|
110
AppKit/NSColor.subproj/NSColor_cmykDevice.m
Executable file
110
AppKit/NSColor.subproj/NSColor_cmykDevice.m
Executable file
@ -0,0 +1,110 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/NSColor_cmykDevice.h>
|
||||
#import <AppKit/NSGraphics.h>
|
||||
#import <AppKit/NSGraphicsContextFunctions.h>
|
||||
#import <AppKit/CoreGraphics.h>
|
||||
|
||||
@implementation NSColor_cmykDevice
|
||||
|
||||
-initWithCyan:(float)cyan magenta:(float)magenta yellow:(float)yellow black:(float)black alpha:(float)alpha {
|
||||
_cyan=cyan;
|
||||
_magenta=magenta;
|
||||
_yellow=yellow;
|
||||
_black=black;
|
||||
_alpha=alpha;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)encodeWithCoder:(NSCoder *)coder {
|
||||
[coder encodeObject:[self colorSpaceName]];
|
||||
[coder encodeValuesOfObjCTypes:"fffff",&_cyan,&_magenta,&_yellow,&_black,&_alpha];
|
||||
}
|
||||
|
||||
-(BOOL)isEqual:otherObject {
|
||||
if(self==otherObject)
|
||||
return YES;
|
||||
|
||||
if([otherObject isKindOfClass:[self class]]){
|
||||
NSColor_cmykDevice *other=otherObject;
|
||||
|
||||
return (_cyan==other->_cyan && _magenta==other->_magenta &&
|
||||
_yellow==other->_yellow && _black==other->_black && _alpha==other->_alpha);
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
||||
- (NSString *)description
|
||||
{
|
||||
return [NSString stringWithFormat:@"<%@ cyan: %f magenta: %f yellow: %f black: %f alpha: %f>",
|
||||
[[self class] description], _cyan, _magenta, _yellow, _black, _alpha];
|
||||
}
|
||||
|
||||
+(NSColor *)colorWithCyan:(float)cyan magenta:(float)magenta yellow:(float)yellow black:(float)black alpha:(float)alpha {
|
||||
return [[[self alloc] initWithCyan:cyan magenta:magenta yellow:yellow black:black alpha:alpha] autorelease];
|
||||
}
|
||||
|
||||
-(NSString *)colorSpaceName {
|
||||
return NSDeviceCMYKColorSpace;
|
||||
}
|
||||
|
||||
-(void)getCyan:(float *)cyan magenta:(float *)magenta yellow:(float *)yellow black:(float *)black alpha:(float *)alpha {
|
||||
if(cyan!=NULL)
|
||||
*cyan = _cyan;
|
||||
if(magenta!=NULL)
|
||||
*magenta = _magenta;
|
||||
if(yellow!=NULL)
|
||||
*yellow = _yellow;
|
||||
if(black!=NULL)
|
||||
*black = _black;
|
||||
if(alpha!=NULL)
|
||||
*alpha = _alpha;
|
||||
}
|
||||
|
||||
-(float)alphaComponent {
|
||||
return _alpha;
|
||||
}
|
||||
|
||||
// ahh, subtractive color space.
|
||||
-(NSColor *)colorUsingColorSpaceName:(NSString *)colorSpace device:(NSDictionary *)device {
|
||||
if([colorSpace isEqualToString:[self colorSpaceName]])
|
||||
return self;
|
||||
|
||||
if([colorSpace isEqualToString:NSCalibratedRGBColorSpace] || colorSpace == nil) {
|
||||
float white = 1 - _black;
|
||||
return [NSColor colorWithCalibratedRed:(_cyan > white ? 0 : white - _cyan)
|
||||
green:(_magenta > white ? 0 : white - _magenta)
|
||||
blue:(_yellow > white ? 0 : white - _yellow)
|
||||
alpha:_alpha];
|
||||
}
|
||||
|
||||
if([colorSpace isEqualToString:NSCalibratedWhiteColorSpace]) {
|
||||
float white = 1 - _cyan - _magenta - _yellow - _black;
|
||||
return [NSColor colorWithCalibratedWhite:(white > 0 ? white : 0) alpha:_alpha];
|
||||
}
|
||||
|
||||
return [super colorUsingColorSpaceName:colorSpace device:device];
|
||||
}
|
||||
|
||||
-(void)set {
|
||||
// temporary fix
|
||||
NSColor *convertedColor = [self colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
|
||||
|
||||
CGContextSetCalibratedRGBColor(NSCurrentGraphicsPort(),
|
||||
[convertedColor redComponent],
|
||||
[convertedColor greenComponent],
|
||||
[convertedColor blueComponent], _alpha);
|
||||
|
||||
// CGContextSetDeviceCMYKColor(NSCurrentGraphicsPort(),_cyan,_magenta,_yellow,_black,_alpha);
|
||||
}
|
||||
|
||||
@end
|
20
AppKit/NSColor.subproj/NSColor_rgbCalibrated.h
Executable file
20
AppKit/NSColor.subproj/NSColor_rgbCalibrated.h
Executable file
@ -0,0 +1,20 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/NSColor.h>
|
||||
|
||||
@interface NSColor_rgbCalibrated : NSColor {
|
||||
float _red,_green,_blue,_alpha;
|
||||
}
|
||||
|
||||
-initWithRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha;
|
||||
|
||||
+(NSColor *)colorWithRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha;
|
||||
+(NSColor *)colorWithHue:(float)hue saturation:(float)saturation brightness:(float)brightness alpha:(float)alpha;
|
||||
|
||||
@end
|
109
AppKit/NSColor.subproj/NSColor_rgbCalibrated.m
Executable file
109
AppKit/NSColor.subproj/NSColor_rgbCalibrated.m
Executable file
@ -0,0 +1,109 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/NSColor_rgbCalibrated.h>
|
||||
#import <AppKit/NSGraphics.h>
|
||||
#import <AppKit/NSGraphicsContextFunctions.h>
|
||||
#import <AppKit/CoreGraphics.h>
|
||||
|
||||
#import <AppKit/conversions.h>
|
||||
|
||||
@implementation NSColor_rgbCalibrated
|
||||
|
||||
-initWithRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha {
|
||||
_red=red;
|
||||
_green=green;
|
||||
_blue=blue;
|
||||
_alpha=alpha;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)encodeWithCoder:(NSCoder *)coder {
|
||||
[coder encodeObject:[self colorSpaceName]];
|
||||
[coder encodeValuesOfObjCTypes:"ffff",&_red,&_green,&_blue,&_alpha];
|
||||
}
|
||||
|
||||
-(BOOL)isEqual:otherObject {
|
||||
if(self==otherObject)
|
||||
return YES;
|
||||
|
||||
if([otherObject isKindOfClass:[self class]]){
|
||||
NSColor_rgbCalibrated *other=otherObject;
|
||||
|
||||
return (_red==other->_red && _green==other->_green &&
|
||||
_blue==other->_blue && _alpha==other->_alpha);
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (NSString *)description
|
||||
{
|
||||
return [NSString stringWithFormat:@"<%@ red: %f green: %f blue: %f alpha: %f>",
|
||||
[[self class] description], _red, _green, _blue, _alpha];
|
||||
}
|
||||
|
||||
+(NSColor *)colorWithRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha {
|
||||
return [[[self alloc] initWithRed:red green:green blue:blue alpha:alpha] autorelease];
|
||||
}
|
||||
|
||||
+(NSColor *)colorWithHue:(float)hue saturation:(float)saturation brightness:(float)brightness alpha:(float)alpha {
|
||||
float red,green,blue;
|
||||
|
||||
NSColorHSBToRGB(hue,saturation,brightness,&red,&green,&blue);
|
||||
|
||||
return [[[self alloc] initWithRed:red green:green blue:blue alpha:alpha] autorelease];
|
||||
}
|
||||
|
||||
-(void)getRed:(float *)red green:(float *)green blue:(float *)blue alpha:(float *)alpha {
|
||||
if(red!=NULL)
|
||||
*red = _red;
|
||||
if(green!=NULL)
|
||||
*green = _green;
|
||||
if(blue!=NULL)
|
||||
*blue = _blue;
|
||||
if(alpha!=NULL)
|
||||
*alpha = _alpha;
|
||||
}
|
||||
|
||||
-(void)getHue:(float *)huep saturation:(float *)saturationp brightness:(float *)brightnessp alpha:(float *)alphap {
|
||||
|
||||
NSColorRGBToHSB(_red,_green,_blue,huep,saturationp,brightnessp);
|
||||
|
||||
if(alphap!=NULL)
|
||||
*alphap=_alpha;
|
||||
}
|
||||
|
||||
-(float)alphaComponent {
|
||||
return _alpha;
|
||||
}
|
||||
|
||||
-(NSString *)colorSpaceName {
|
||||
return NSCalibratedRGBColorSpace;
|
||||
}
|
||||
|
||||
-(NSColor *)colorUsingColorSpaceName:(NSString *)colorSpace device:(NSDictionary *)device {
|
||||
if([colorSpace isEqualToString:NSCalibratedRGBColorSpace] || colorSpace == nil)
|
||||
return self;
|
||||
|
||||
if([colorSpace isEqualToString:NSCalibratedWhiteColorSpace])
|
||||
return [NSColor colorWithCalibratedWhite:(_red+_green+_blue)/3 alpha:_alpha];
|
||||
|
||||
// FIX, This is not accurate
|
||||
if([colorSpace isEqualToString:NSDeviceCMYKColorSpace])
|
||||
return [NSColor colorWithDeviceCyan:1.0-_red magenta:1.0-_green yellow:1.0-_blue black:0.0 alpha:_alpha];
|
||||
|
||||
return [super colorUsingColorSpaceName:colorSpace device:device];
|
||||
}
|
||||
|
||||
-(void)set {
|
||||
CGContextSetCalibratedRGBColor(NSCurrentGraphicsPort(),_red,_green,_blue,_alpha);
|
||||
}
|
||||
|
||||
@end
|
20
AppKit/NSColor.subproj/NSColor_rgbDevice.h
Executable file
20
AppKit/NSColor.subproj/NSColor_rgbDevice.h
Executable file
@ -0,0 +1,20 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/NSColor.h>
|
||||
|
||||
@interface NSColor_rgbDevice : NSColor {
|
||||
float _red,_green,_blue,_alpha;
|
||||
}
|
||||
|
||||
-initWithRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha;
|
||||
|
||||
+(NSColor *)colorWithRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha;
|
||||
+(NSColor *)colorWithHue:(float)hue saturation:(float)saturation brightness:(float)brightness alpha:(float)alpha;
|
||||
|
||||
@end
|
115
AppKit/NSColor.subproj/NSColor_rgbDevice.m
Executable file
115
AppKit/NSColor.subproj/NSColor_rgbDevice.m
Executable file
@ -0,0 +1,115 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/NSColor_rgbDevice.h>
|
||||
#import <AppKit/NSGraphics.h>
|
||||
#import <AppKit/NSGraphicsContextFunctions.h>
|
||||
#import <AppKit/CoreGraphics.h>
|
||||
|
||||
#import <AppKit/conversions.h>
|
||||
|
||||
@implementation NSColor_rgbDevice
|
||||
|
||||
-initWithRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha {
|
||||
_red=red;
|
||||
_green=green;
|
||||
_blue=blue;
|
||||
_alpha=alpha;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)encodeWithCoder:(NSCoder *)coder {
|
||||
[coder encodeObject:[self colorSpaceName]];
|
||||
[coder encodeValuesOfObjCTypes:"ffff",&_red,&_green,&_blue,&_alpha];
|
||||
}
|
||||
|
||||
-(BOOL)isEqual:otherObject {
|
||||
if(self==otherObject)
|
||||
return YES;
|
||||
|
||||
if([otherObject isKindOfClass:[self class]]){
|
||||
NSColor_rgbDevice *other=otherObject;
|
||||
|
||||
return (_red==other->_red && _green==other->_green &&
|
||||
_blue==other->_blue && _alpha==other->_alpha);
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (NSString *)description
|
||||
{
|
||||
return [NSString stringWithFormat:@"<%@ red: %f green: %f blue: %f alpha: %f>",
|
||||
[[self class] description], _red, _green, _blue, _alpha];
|
||||
}
|
||||
|
||||
+(NSColor *)colorWithRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha {
|
||||
return [[[self alloc] initWithRed:red green:green blue:blue alpha:alpha] autorelease];
|
||||
}
|
||||
|
||||
+(NSColor *)colorWithHue:(float)hue saturation:(float)saturation brightness:(float)brightness alpha:(float)alpha {
|
||||
float red,green,blue;
|
||||
|
||||
NSColorHSBToRGB(hue,saturation,brightness,&red,&green,&blue);
|
||||
|
||||
return [[[self alloc] initWithRed:red green:green blue:blue alpha:alpha] autorelease];
|
||||
}
|
||||
|
||||
-(void)getRed:(float *)red green:(float *)green blue:(float *)blue alpha:(float *)alpha {
|
||||
if(red!=NULL)
|
||||
*red = _red;
|
||||
if(green!=NULL)
|
||||
*green = _green;
|
||||
if(blue!=NULL)
|
||||
*blue = _blue;
|
||||
if(alpha!=NULL)
|
||||
*alpha = _alpha;
|
||||
}
|
||||
|
||||
-(void)getHue:(float *)huep saturation:(float *)saturationp brightness:(float *)brightnessp alpha:(float *)alphap {
|
||||
|
||||
NSColorRGBToHSB(_red,_green,_blue,huep,saturationp,brightnessp);
|
||||
|
||||
if(alphap!=NULL)
|
||||
*alphap=_alpha;
|
||||
}
|
||||
|
||||
-(float)alphaComponent {
|
||||
return _alpha;
|
||||
}
|
||||
|
||||
-(NSColor *)colorUsingColorSpaceName:(NSString *)colorSpace device:(NSDictionary *)device {
|
||||
if([colorSpace isEqualToString:NSDeviceRGBColorSpace] || colorSpace==nil)
|
||||
return self;
|
||||
|
||||
if([colorSpace isEqualToString:NSDeviceWhiteColorSpace])
|
||||
return [NSColor colorWithDeviceWhite:(_red+_green+_blue)/3 alpha:_alpha];
|
||||
|
||||
if([colorSpace isEqualToString:NSDeviceCMYKColorSpace])
|
||||
return [NSColor colorWithDeviceCyan:1.0-_red magenta:1.0-_green yellow:1.0-_blue black:0.0 alpha:_alpha];
|
||||
|
||||
// FIX, These are not accurate
|
||||
if([colorSpace isEqualToString:NSCalibratedRGBColorSpace])
|
||||
return [NSColor colorWithCalibratedRed:_red green:_green blue:_blue alpha:_alpha];
|
||||
|
||||
if([colorSpace isEqualToString:NSCalibratedWhiteColorSpace])
|
||||
return [NSColor colorWithCalibratedWhite:(_red+_green+_blue)/3 alpha:_alpha];
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
-(NSString *)colorSpaceName {
|
||||
return NSDeviceRGBColorSpace;
|
||||
}
|
||||
|
||||
-(void)set {
|
||||
CGContextSetDeviceRGBColor(NSCurrentGraphicsPort(),_red,_green,_blue,_alpha);
|
||||
}
|
||||
|
||||
@end
|
28
AppKit/NSColor.subproj/NSColor_whiteCalibrated.h
Executable file
28
AppKit/NSColor.subproj/NSColor_whiteCalibrated.h
Executable file
@ -0,0 +1,28 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/NSColor.h>
|
||||
|
||||
@interface NSColor_whiteCalibrated : NSColor {
|
||||
float _white;
|
||||
float _alpha;
|
||||
}
|
||||
|
||||
-initWithGray:(float)gray alpha:(float)alpha;
|
||||
|
||||
-(void)getWhite:(float *)white alpha:(float *)alpha;
|
||||
|
||||
+(NSColor *)colorWithGray:(float)gray alpha:(float)alpha;
|
||||
|
||||
+(NSColor *)blackColor;
|
||||
+(NSColor *)darkGrayColor;
|
||||
+(NSColor *)lightGrayColor;
|
||||
+(NSColor *)whiteColor;
|
||||
+(NSColor *)grayColor;
|
||||
|
||||
@end
|
128
AppKit/NSColor.subproj/NSColor_whiteCalibrated.m
Executable file
128
AppKit/NSColor.subproj/NSColor_whiteCalibrated.m
Executable file
@ -0,0 +1,128 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/NSColor_whiteCalibrated.h>
|
||||
#import <AppKit/NSGraphics.h>
|
||||
#import <AppKit/NSGraphicsContextFunctions.h>
|
||||
#import <AppKit/CoreGraphics.h>
|
||||
|
||||
@implementation NSColor_whiteCalibrated
|
||||
|
||||
-initWithGray:(float)gray alpha:(float)alpha {
|
||||
_white=gray;
|
||||
_alpha=alpha;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)encodeWithCoder:(NSCoder *)coder {
|
||||
[coder encodeObject:[self colorSpaceName]];
|
||||
[coder encodeValuesOfObjCTypes:"ff",&_white,&_alpha];
|
||||
}
|
||||
|
||||
-(BOOL)isEqual:otherObject {
|
||||
if(self==otherObject)
|
||||
return YES;
|
||||
|
||||
if([otherObject isKindOfClass:[self class]]){
|
||||
NSColor_whiteCalibrated *other=otherObject;
|
||||
|
||||
return (_white==other->_white && _alpha==other->_alpha);
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (NSString *)description
|
||||
{
|
||||
return [NSString stringWithFormat:@"<%@ _white: %f alpha: %f>",
|
||||
[[self class] description], _white, _alpha];
|
||||
}
|
||||
|
||||
+(NSColor *)colorWithGray:(float)gray alpha:(float)alpha {
|
||||
return [[[self alloc] initWithGray:gray alpha:alpha] autorelease];
|
||||
}
|
||||
|
||||
+(NSColor *)blackColor {
|
||||
static NSColor *shared=nil;
|
||||
|
||||
if(shared==nil)
|
||||
shared=[[NSColor_whiteCalibrated alloc] initWithGray:0 alpha:1.0];
|
||||
|
||||
return shared;
|
||||
}
|
||||
|
||||
+(NSColor *)darkGrayColor {
|
||||
static NSColor *shared=nil;
|
||||
|
||||
if(shared==nil)
|
||||
shared=[[NSColor_whiteCalibrated alloc] initWithGray:0.333 alpha:1.0];
|
||||
|
||||
return shared;
|
||||
}
|
||||
|
||||
+(NSColor *)lightGrayColor {
|
||||
static NSColor *shared=nil;
|
||||
|
||||
if(shared==nil)
|
||||
shared=[[NSColor_whiteCalibrated alloc] initWithGray:0.667 alpha:1.0];
|
||||
|
||||
return shared;
|
||||
}
|
||||
|
||||
+(NSColor *)whiteColor {
|
||||
static NSColor *shared=nil;
|
||||
|
||||
if(shared==nil)
|
||||
shared=[[NSColor_whiteCalibrated alloc] initWithGray:1 alpha:1.0];
|
||||
|
||||
return shared;
|
||||
}
|
||||
|
||||
+(NSColor *)grayColor {
|
||||
static NSColor *shared=nil;
|
||||
|
||||
if(shared==nil)
|
||||
shared=[[NSColor_whiteCalibrated alloc] initWithGray:0.5 alpha:1.0];
|
||||
|
||||
return shared;
|
||||
}
|
||||
|
||||
-(NSString *)colorSpaceName {
|
||||
return NSCalibratedWhiteColorSpace;
|
||||
}
|
||||
|
||||
-(void)getWhite:(float *)white alpha:(float *)alpha {
|
||||
if(white!=NULL)
|
||||
*white = _white;
|
||||
if(alpha!=NULL)
|
||||
*alpha = _alpha;
|
||||
}
|
||||
|
||||
-(float)alphaComponent {
|
||||
return _alpha;
|
||||
}
|
||||
|
||||
-(NSColor *)colorUsingColorSpaceName:(NSString *)colorSpace device:(NSDictionary *)device {
|
||||
if([colorSpace isEqualToString:NSCalibratedWhiteColorSpace])
|
||||
return self;
|
||||
|
||||
if([colorSpace isEqualToString:NSCalibratedRGBColorSpace] || colorSpace == nil)
|
||||
return [NSColor colorWithCalibratedRed:_white green:_white blue:_white alpha:_alpha];
|
||||
|
||||
if([colorSpace isEqualToString:NSDeviceCMYKColorSpace])
|
||||
return [NSColor colorWithDeviceCyan:0 magenta:0 yellow:0 black:1-_white alpha:_alpha];
|
||||
|
||||
return [super colorUsingColorSpaceName:colorSpace device:device];
|
||||
}
|
||||
|
||||
-(void)set {
|
||||
CGContextSetCalibratedGrayColor(NSCurrentGraphicsPort(),_white,_alpha);
|
||||
}
|
||||
|
||||
@end
|
20
AppKit/NSColor.subproj/NSColor_whiteDevice.h
Executable file
20
AppKit/NSColor.subproj/NSColor_whiteDevice.h
Executable file
@ -0,0 +1,20 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/NSColor.h>
|
||||
|
||||
@interface NSColor_whiteDevice : NSColor {
|
||||
float _white;
|
||||
float _alpha;
|
||||
}
|
||||
|
||||
-initWithGray:(float)gray alpha:(float)alpha;
|
||||
|
||||
+(NSColor *)colorWithGray:(float)gray alpha:(float)alpha;
|
||||
|
||||
@end
|
70
AppKit/NSColor.subproj/NSColor_whiteDevice.m
Executable file
70
AppKit/NSColor.subproj/NSColor_whiteDevice.m
Executable file
@ -0,0 +1,70 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/NSColor_whiteDevice.h>
|
||||
#import <AppKit/NSGraphics.h>
|
||||
#import <AppKit/NSGraphicsContextFunctions.h>
|
||||
#import <AppKit/CoreGraphics.h>
|
||||
|
||||
@implementation NSColor_whiteDevice
|
||||
|
||||
-initWithGray:(float)gray alpha:(float)alpha {
|
||||
_white=gray;
|
||||
_alpha=alpha;
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)encodeWithCoder:(NSCoder *)coder {
|
||||
[coder encodeObject:[self colorSpaceName]];
|
||||
[coder encodeValuesOfObjCTypes:"ff",&_white,&_alpha];
|
||||
}
|
||||
|
||||
-(BOOL)isEqual:otherObject {
|
||||
if(self==otherObject)
|
||||
return YES;
|
||||
|
||||
if([otherObject isKindOfClass:[self class]]){
|
||||
NSColor_whiteDevice *other=otherObject;
|
||||
|
||||
return (_white==other->_white && _alpha==other->_alpha);
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (NSString *)description
|
||||
{
|
||||
return [NSString stringWithFormat:@"<%@ _white: %f alpha: %f>",
|
||||
[[self class] description], _white, _alpha];
|
||||
}
|
||||
|
||||
+(NSColor *)colorWithGray:(float)gray alpha:(float)alpha {
|
||||
return [[[self alloc] initWithGray:gray alpha:alpha] autorelease];
|
||||
}
|
||||
|
||||
-(NSString *)colorSpaceName {
|
||||
return NSDeviceWhiteColorSpace;
|
||||
}
|
||||
|
||||
-(void)getWhite:(float *)white alpha:(float *)alpha {
|
||||
if(white!=NULL)
|
||||
*white = _white;
|
||||
if(alpha!=NULL)
|
||||
*alpha = _alpha;
|
||||
}
|
||||
|
||||
-(float)alphaComponent {
|
||||
return _alpha;
|
||||
}
|
||||
|
||||
-(void)set {
|
||||
CGContextSetDeviceGrayColor(NSCurrentGraphicsPort(),_white,_alpha);
|
||||
}
|
||||
|
||||
@end
|
75
AppKit/NSColor.subproj/conversions.h
Executable file
75
AppKit/NSColor.subproj/conversions.h
Executable file
@ -0,0 +1,75 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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. */
|
||||
|
||||
// NSColorHSBToRGB, NSColorRGBToHSB
|
||||
// Algorithms from "Computer Graphics Principles and Practice" by Foley, van Dam, Feiner, Hughes
|
||||
|
||||
static inline void NSColorHSBToRGB(float hue,float saturation,float brightness,float *redp,float *greenp,float *bluep) {
|
||||
float red=brightness,green=brightness,blue=brightness;
|
||||
|
||||
if(saturation!=0){
|
||||
float frac,p,q,t;
|
||||
int intHue;
|
||||
|
||||
hue=hue*360;
|
||||
if(hue==360)
|
||||
hue=0;
|
||||
hue=hue/60;
|
||||
intHue=hue;
|
||||
frac=hue-intHue;
|
||||
|
||||
p=brightness*(1.0-saturation);
|
||||
q=brightness*(1.0-(saturation*frac));
|
||||
t=brightness*(1.0-(saturation*(1.0-frac)));
|
||||
switch(intHue){
|
||||
case 0: red=brightness; green=t; blue=p; break;
|
||||
case 1: red=q; green=brightness; blue=p; break;
|
||||
case 2: red=p; green=brightness; blue=t; break;
|
||||
case 3: red=p; green=q; blue=brightness; break;
|
||||
case 4: red=t; green=p; blue=brightness; break;
|
||||
case 5: red=brightness; green=p; blue=q; break;
|
||||
}
|
||||
}
|
||||
|
||||
*redp=red;
|
||||
*greenp=green;
|
||||
*bluep=blue;
|
||||
}
|
||||
|
||||
static inline void NSColorRGBToHSB(float red,float green,float blue,float *huep,float *saturationp,float *brightnessp) {
|
||||
float hue=0,saturation=0,brightness,min,max;
|
||||
|
||||
max=MAX(red,MAX(green,blue));
|
||||
min=MIN(red,MIN(green,blue));
|
||||
|
||||
brightness=max;
|
||||
if(max>0){
|
||||
float delta=max-min;
|
||||
|
||||
saturation=delta/max;
|
||||
if(red==max)
|
||||
hue=(green-blue)/delta;
|
||||
else if(green==max)
|
||||
hue=2+(blue-red)/delta;
|
||||
else if(blue==max)
|
||||
hue=4+(red-green)/delta;
|
||||
hue=hue*60;
|
||||
if(hue<0)
|
||||
hue=hue+360;
|
||||
}
|
||||
|
||||
if(hue!=hue)
|
||||
hue=0;
|
||||
|
||||
if(huep!=NULL)
|
||||
*huep=hue/360.0;
|
||||
if(saturationp!=NULL)
|
||||
*saturationp=saturation;
|
||||
if(brightnessp!=NULL)
|
||||
*brightnessp=brightness;
|
||||
}
|
42
AppKit/NSColorList.h
Executable file
42
AppKit/NSColorList.h
Executable file
@ -0,0 +1,42 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/AppKit.h>
|
||||
|
||||
@class NSColor;
|
||||
|
||||
APPKIT_EXPORT NSString *NSColorListDidChangeNotification;
|
||||
|
||||
@interface NSColorList : NSObject // <NSCoding>
|
||||
{
|
||||
NSMutableArray *_keys;
|
||||
NSMutableArray *_colors;
|
||||
NSString *_name;
|
||||
NSString *_path;
|
||||
}
|
||||
|
||||
+(NSArray *)availableColorLists;
|
||||
|
||||
-initWithName:(NSString *)name fromFile:(NSString *)path;
|
||||
-initWithName:(NSString *)name;
|
||||
|
||||
+(NSColorList *)colorListNamed:(NSString *)name;
|
||||
|
||||
-(NSString *)name;
|
||||
-(NSArray *)allKeys;
|
||||
-(NSColor *)colorWithKey:(NSString *)key;
|
||||
|
||||
-(void)setColor:(NSColor *)color forKey:(NSString *)key;
|
||||
-(void)removeColorWithKey:(NSString *)key;
|
||||
-(void)insertColor:(NSColor *)color key:(NSString *)key atIndex:(unsigned)index;
|
||||
|
||||
-(void)writeToFile:(NSString *)path;
|
||||
-(void)removeFile;
|
||||
|
||||
@end
|
||||
|
333
AppKit/NSColorList.m
Executable file
333
AppKit/NSColorList.m
Executable file
@ -0,0 +1,333 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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 - David Young <daver@geeks.org>
|
||||
#import <AppKit/NSColorList.h>
|
||||
|
||||
NSString *NSColorListDidChangeNotification = @"NSColorListDidChangeNotification";
|
||||
|
||||
@implementation NSColorList
|
||||
|
||||
static NSMutableDictionary *_namedColorLists = nil;
|
||||
|
||||
+ (void)_createDefaultColorLists
|
||||
{
|
||||
static struct WebColor {
|
||||
NSString *name;
|
||||
unsigned value;
|
||||
} webColors[217]={
|
||||
{ @"Alice Blue",0xF0F8FF },
|
||||
{ @"Antique White",0xFAEBD7 },
|
||||
{ @"Aqua",0x00FFFF },
|
||||
{ @"Aquamarine",0x7FFFD4 },
|
||||
{ @"Azure",0xF0FFFF },
|
||||
{ @"Beige",0xF5F5DC },
|
||||
{ @"Bisque",0xFFE4C4 },
|
||||
{ @"Black",0x000000 },
|
||||
{ @"Blanched Almond",0xFFEBCD },
|
||||
{ @"Blue",0x0000FF },
|
||||
{ @"Blue Violet",0x8A2BE2 },
|
||||
{ @"Brown",0xA52A2A },
|
||||
{ @"Burly Wood",0xDEB887 },
|
||||
{ @"Cadet Blue",0x5F9EA0 },
|
||||
{ @"Chartreuse",0x7FFF00 },
|
||||
{ @"Chocolate",0xD2691E },
|
||||
{ @"Coral",0xFF7F50 },
|
||||
{ @"Cornflower Blue",0x6495ED },
|
||||
{ @"Cornsilk",0xFFF8DC },
|
||||
{ @"Crimson",0xDC143C },
|
||||
{ @"Cyan",0x00FFFF },
|
||||
{ @"Dark Blue",0x00008B },
|
||||
{ @"Dark Cyan",0x008B8B },
|
||||
{ @"Dark GoldenRod",0xB8860B },
|
||||
{ @"Dark Gray",0xA9A9A9 },
|
||||
{ @"Dark Green",0x006400 },
|
||||
{ @"Dark Khaki",0xBDB76B },
|
||||
{ @"Dark Magenta",0x8B008B },
|
||||
{ @"Dark Olive Green",0x556B2F },
|
||||
{ @"Dark Orange",0xFF8C00 },
|
||||
{ @"Dark Orchid",0x9932CC },
|
||||
{ @"Dark Red",0x8B0000 },
|
||||
{ @"Dark Salmon",0xE9967A },
|
||||
{ @"Dark Sea Green",0x8FBC8F },
|
||||
{ @"Dark Slate Blue",0x483D8B },
|
||||
{ @"Dark Slate Gray",0x2F4F4F },
|
||||
{ @"Dark Turquoise",0x00CED1 },
|
||||
{ @"Dark Violet",0x9400D3 },
|
||||
{ @"Deep Pink",0xFF1493 },
|
||||
{ @"Deep Sky Blue",0x00BFFF },
|
||||
{ @"Dim Gray",0x696969 },
|
||||
{ @"Dodger Blue",0x1E90FF },
|
||||
{ @"Fire Brick",0xB22222 },
|
||||
{ @"Floral White",0xFFFAF0 },
|
||||
{ @"Forest Green",0x228B22 },
|
||||
{ @"Gainsboro",0xDCDCDC },
|
||||
{ @"Ghost White",0xF8F8FF },
|
||||
{ @"Gold",0xFFD700 },
|
||||
{ @"Golden Rod",0xDAA520 },
|
||||
{ @"Gray",0x808080 },
|
||||
{ @"Green",0x008000 },
|
||||
{ @"Green Yellow",0xADFF2F },
|
||||
{ @"Honey Dew",0xF0FFF0 },
|
||||
{ @"Hot Pink",0xFF69B4 },
|
||||
{ @"Indian Red",0xCD5C5C },
|
||||
{ @"Indigo",0x4B0082 },
|
||||
{ @"Ivory",0xFFFFF0 },
|
||||
{ @"Khaki",0xF0E68C },
|
||||
{ @"Lavender",0xE6E6FA },
|
||||
{ @"Lavender Blush",0xFFF0F5 },
|
||||
{ @"Lawn Green",0x7CFC00 },
|
||||
{ @"Lemon Chiffon",0xFFFACD },
|
||||
{ @"Light Blue",0xADD8E6 },
|
||||
{ @"Light Coral",0xF08080 },
|
||||
{ @"Light Cyan",0xE0FFFF },
|
||||
{ @"Light Golden Rod Yellow",0xFAFAD2 },
|
||||
{ @"Light Gray",0xD3D3D3 },
|
||||
{ @"Light Green",0x90EE90 },
|
||||
{ @"Light Pink",0xFFB6C1 },
|
||||
{ @"Light Salmon",0xFFA07A },
|
||||
{ @"Light Sea Green",0x20B2AA },
|
||||
{ @"Light Sky Blue",0x87CEFA },
|
||||
{ @"Light Slate Blue",0x8470FF },
|
||||
{ @"Light Slate Gray",0x778899 },
|
||||
{ @"Light Steel Blue",0xB0C4DE },
|
||||
{ @"Light Yellow",0xFFFFE0 },
|
||||
{ @"Lime",0x00FF00 },
|
||||
{ @"Lime Green",0x32CD32 },
|
||||
{ @"Linen",0xFAF0E6 },
|
||||
{ @"Magenta",0xFF00FF },
|
||||
{ @"Maroon",0x800000 },
|
||||
{ @"Medium Aqua Marine",0x66CDAA },
|
||||
{ @"Medium Blue",0x0000CD },
|
||||
{ @"Medium Orchid",0xBA55D3 },
|
||||
{ @"Medium Purple",0x9370D8 },
|
||||
{ @"Medium Sea Green",0x3CB371 },
|
||||
{ @"Medium Slate Blue",0x7B68EE },
|
||||
{ @"Medium Spring Green",0x00FA9A },
|
||||
{ @"Medium Turquoise",0x48D1CC },
|
||||
{ @"Medium Violet Red",0xC71585 },
|
||||
{ @"Midnight Blue",0x191970 },
|
||||
{ @"Mint Cream",0xF5FFFA },
|
||||
{ @"Misty Rose",0xFFE4E1 },
|
||||
{ @"Moccasin",0xFFE4B5 },
|
||||
{ @"Navajo White",0xFFDEAD },
|
||||
{ @"Navy",0x000080 },
|
||||
{ @"Old Lace",0xFDF5E6 },
|
||||
{ @"Olive",0x808000 },
|
||||
{ @"Olive Drab",0x6B8E23 },
|
||||
{ @"Orange",0xFFA500 },
|
||||
{ @"Orange Red",0xFF4500 },
|
||||
{ @"Orchid",0xDA70D6 },
|
||||
{ @"Pale Golden Rod",0xEEE8AA },
|
||||
{ @"Pale Green",0x98FB98 },
|
||||
{ @"Pale Turquoise",0xAFEEEE },
|
||||
{ @"PaleViolet Red",0xD87093 },
|
||||
{ @"Papaya Whip",0xFFEFD5 },
|
||||
{ @"Peach Puff",0xFFDAB9 },
|
||||
{ @"Peru",0xCD853F },
|
||||
{ @"Pink",0xFFC0CB },
|
||||
{ @"Plum",0xDDA0DD },
|
||||
{ @"Powder Blue",0xB0E0E6 },
|
||||
{ @"Purple",0x800080 },
|
||||
{ @"Red",0xFF0000 },
|
||||
{ @"Rosy Brown",0xBC8F8F },
|
||||
{ @"Royal Blue",0x4169E1 },
|
||||
{ @"Saddle Brown",0x8B4513 },
|
||||
{ @"Salmon",0xFA8072 },
|
||||
{ @"Sandy Brown",0xF4A460 },
|
||||
{ @"Sea Green",0x2E8B57 },
|
||||
{ @"Sea Shell",0xFFF5EE },
|
||||
{ @"Sienna",0xA0522D },
|
||||
{ @"Silver",0xC0C0C0 },
|
||||
{ @"Sky Blue",0x87CEEB },
|
||||
{ @"Slate Blue",0x6A5ACD },
|
||||
{ @"Slate Gray",0x708090 },
|
||||
{ @"Snow",0xFFFAFA },
|
||||
{ @"Spring Green",0x00FF7F },
|
||||
{ @"Steel Blue",0x4682B4 },
|
||||
{ @"Tan",0xD2B48C },
|
||||
{ @"Teal",0x008080 },
|
||||
{ @"Thistle",0xD8BFD8 },
|
||||
{ @"Tomato",0xFF6347 },
|
||||
{ @"Turquoise",0x40E0D0 },
|
||||
{ @"Violet",0xEE82EE },
|
||||
{ @"Violet Red",0xD02090 },
|
||||
{ @"Wheat",0xF5DEB3 },
|
||||
{ @"White",0xFFFFFF },
|
||||
{ @"White Smoke",0xF5F5F5 },
|
||||
{ @"Yellow",0xFFFF00 },
|
||||
{ @"Yellow Green",0x9ACD32 },
|
||||
{ nil, 0x0 }
|
||||
};
|
||||
|
||||
NSColorList *basicColorList = [[[NSColorList alloc] initWithName:@"Basic"] autorelease];
|
||||
NSColorList *systemColorList = [[[NSColorList alloc] initWithName:@"System"] autorelease];
|
||||
NSColorList *webColorList = [[[NSColorList alloc] initWithName:@"Web"] autorelease];
|
||||
int i;
|
||||
|
||||
for(i=0;webColors[i].name!=nil;i++){
|
||||
unsigned value=webColors[i].value;
|
||||
float red=((value>>16)&0xFF)/255.0;
|
||||
float green=((value>>8)&0xFF)/255.0;
|
||||
float blue=(value&0xFF)/255.0;
|
||||
NSColor *color=[NSColor colorWithCalibratedRed:red green:green blue:blue alpha:1.0];
|
||||
|
||||
[webColorList setColor:color forKey: webColors[i].name];
|
||||
}
|
||||
|
||||
[basicColorList setColor:[NSColor blackColor] forKey:@"Black"];
|
||||
[basicColorList setColor:[NSColor blueColor] forKey:@"Blue"];
|
||||
[basicColorList setColor:[NSColor brownColor] forKey:@"Brown"];
|
||||
[basicColorList setColor:[NSColor cyanColor] forKey:@"Cyan"];
|
||||
[basicColorList setColor:[NSColor greenColor] forKey:@"Green"];
|
||||
[basicColorList setColor:[NSColor magentaColor] forKey:@"Magenta"];
|
||||
[basicColorList setColor:[NSColor orangeColor] forKey:@"Orange"];
|
||||
[basicColorList setColor:[NSColor purpleColor] forKey:@"Purple"];
|
||||
[basicColorList setColor:[NSColor redColor] forKey:@"Red"];
|
||||
[basicColorList setColor:[NSColor yellowColor] forKey:@"Yellow"];
|
||||
[basicColorList setColor:[NSColor whiteColor] forKey:@"White"];
|
||||
|
||||
[systemColorList setColor:[NSColor controlColor] forKey:@"controlColor"];
|
||||
[systemColorList setColor:[NSColor controlShadowColor] forKey:@"controlShadowColor"];
|
||||
[systemColorList setColor:[NSColor controlDarkShadowColor] forKey:@"controlDarkShadowColor"];
|
||||
[systemColorList setColor:[NSColor controlHighlightColor] forKey:@"controlHighlightColor"];
|
||||
[systemColorList setColor:[NSColor controlLightHighlightColor] forKey:@"controlLightHighlightColor"];
|
||||
[systemColorList setColor:[NSColor controlTextColor] forKey:@"controlTextColor"];
|
||||
[systemColorList setColor:[NSColor controlBackgroundColor] forKey:@"controlBackgroundColor"];
|
||||
[systemColorList setColor:[NSColor textBackgroundColor] forKey:@"textBackgroundColor"];
|
||||
[systemColorList setColor:[NSColor selectedTextColor] forKey:@"selectedTextColor"];
|
||||
[systemColorList setColor:[NSColor selectedControlColor] forKey:@"selectedControlColor"];
|
||||
[systemColorList setColor:[NSColor selectedControlTextColor] forKey:@"selectedControlTextColor"];
|
||||
[systemColorList setColor:[NSColor scrollBarColor] forKey:@"scrollBarColor"];
|
||||
//[systemColorList setColor:[NSColor gridColor] forKey:@"gridColor"];
|
||||
|
||||
|
||||
_namedColorLists = [[NSMutableDictionary alloc] init];
|
||||
[_namedColorLists setObject:basicColorList forKey:@"Basic"];
|
||||
[_namedColorLists setObject:systemColorList forKey:@"System"];
|
||||
[_namedColorLists setObject:webColorList forKey:@"Web"];
|
||||
}
|
||||
|
||||
+ (NSArray *)availableColorLists
|
||||
{
|
||||
if (_namedColorLists == nil)
|
||||
[NSColorList _createDefaultColorLists];
|
||||
|
||||
return [_namedColorLists allValues];
|
||||
}
|
||||
|
||||
- (id)initWithName:(NSString *)name fromFile:(NSString *)path
|
||||
{
|
||||
_keys = [[NSMutableArray alloc] init];
|
||||
_colors = [[NSMutableArray alloc] init];
|
||||
_name = [name copy];
|
||||
_path = [path copy];
|
||||
|
||||
if (_path != nil) {
|
||||
// FIX, file loading doesnt work for NSColorList
|
||||
// DYFIX: load list
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithName:(NSString *)name
|
||||
{
|
||||
return [self initWithName:name fromFile:nil];
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[_keys release];
|
||||
[_colors release];
|
||||
[_name release];
|
||||
[_path release];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
+ (NSColorList *)colorListNamed:(NSString *)name
|
||||
{
|
||||
if (_namedColorLists == nil)
|
||||
[NSColorList _createDefaultColorLists];
|
||||
|
||||
return [_namedColorLists objectForKey:name];
|
||||
}
|
||||
|
||||
- (NSString *)name { return _name; }
|
||||
|
||||
- (NSArray *)allKeys { return _keys; }
|
||||
|
||||
- (NSColor *)colorWithKey:(NSString *)soughtKey indexPtr:(unsigned *)index
|
||||
{
|
||||
NSEnumerator *keyEnumerator = [_keys objectEnumerator];
|
||||
NSString *thisKey;
|
||||
|
||||
*index = 0;
|
||||
while (thisKey = [keyEnumerator nextObject]) {
|
||||
if ([thisKey isEqualToString:soughtKey])
|
||||
return [_colors objectAtIndex:*index];
|
||||
(*index)++;
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSColor *)colorWithKey:(NSString *)soughtKey
|
||||
{
|
||||
unsigned index; // unused
|
||||
return [self colorWithKey:soughtKey indexPtr:&index];
|
||||
}
|
||||
|
||||
- (void)setColor:(NSColor *)color forKey:(NSString *)key
|
||||
{
|
||||
unsigned index;
|
||||
|
||||
// if we already have a color with this key, replace it...
|
||||
if ([self colorWithKey:key indexPtr:&index])
|
||||
[_colors replaceObjectAtIndex:index withObject:color];
|
||||
else {
|
||||
[_keys addObject:key]; // otherwise the color/key combo are added to the end of the list
|
||||
[_colors addObject:color];
|
||||
}
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:NSColorListDidChangeNotification object:self];
|
||||
}
|
||||
|
||||
- (void)removeColorWithKey:(NSString *)key
|
||||
{
|
||||
unsigned index;
|
||||
|
||||
if ([self colorWithKey:key indexPtr:&index]) {
|
||||
[_colors removeObjectAtIndex:index];
|
||||
[_keys removeObjectAtIndex:index];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:NSColorListDidChangeNotification object:self];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)insertColor:(NSColor *)color key:(NSString *)key atIndex:(unsigned)index
|
||||
{
|
||||
[_colors insertObject:color atIndex:index];
|
||||
[_keys insertObject:key atIndex:index];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:NSColorListDidChangeNotification object:self];
|
||||
}
|
||||
|
||||
- (void)writeToFile:(NSString *)path
|
||||
{
|
||||
NSUnimplementedMethod();
|
||||
}
|
||||
|
||||
- (void)removeFile
|
||||
{
|
||||
[[NSFileManager defaultManager] removeFileAtPath:_path handler:nil];
|
||||
}
|
||||
|
||||
@end
|
||||
|
75
AppKit/NSColorPanel.h
Executable file
75
AppKit/NSColorPanel.h
Executable file
@ -0,0 +1,75 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/NSPanel.h>
|
||||
#import <AppKit/NSApplication.h>
|
||||
|
||||
@class NSButton, NSColorWell, NSMatrix, NSView, NSColorList, NSSplitView;
|
||||
|
||||
enum {
|
||||
NSGrayModeColorPanel,
|
||||
NSRGBModeColorPanel,
|
||||
NSCMYKModeColorPanel,
|
||||
NSHSBModeColorPanel,
|
||||
NSCustomPaletteModeColorPanel,
|
||||
NSColorListModeColorPanel,
|
||||
NSWheelModeColorPanel
|
||||
};
|
||||
|
||||
APPKIT_EXPORT NSString *NSColorPanelColorDidChangeNotification;
|
||||
|
||||
@interface NSColorPanel : NSPanel {
|
||||
NSButton *setColorButton;
|
||||
NSColorWell *colorWell;
|
||||
NSMatrix *colorPickersMatrix;
|
||||
NSView *colorPickerView;
|
||||
NSView *currentColorPickerView;
|
||||
NSView *swatchView;
|
||||
NSSplitView *splitView;
|
||||
|
||||
BOOL _showsAlpha;
|
||||
BOOL _continuous;
|
||||
int _mode;
|
||||
NSMutableArray *_colorPickers;
|
||||
id _target;
|
||||
SEL _action;
|
||||
}
|
||||
|
||||
+(BOOL)sharedColorPanelExists;
|
||||
+(NSColorPanel *)sharedColorPanel;
|
||||
|
||||
+(void)setPickerMask:(int)mask;
|
||||
+(void)setPickerMode:(int)mode;
|
||||
|
||||
+(BOOL)dragColor:(NSColor *)color withEvent:(NSEvent *)event fromView:(NSView *)view;
|
||||
|
||||
-(NSColor *)color;
|
||||
-(float)alpha;
|
||||
-(int)mode;
|
||||
-(BOOL)showsAlpha;
|
||||
-(BOOL)isContinuous;
|
||||
-(NSView *)accessoryView;
|
||||
|
||||
-(void)setColor:(NSColor *)color;
|
||||
-(void)setMode:(int)mode;
|
||||
-(void)setShowsAlpha:(BOOL)flag;
|
||||
-(void)setContinuous:(BOOL)flag;
|
||||
-(void)setAccessoryView:(NSView *)view;
|
||||
|
||||
-(void)setAction:(SEL)action;
|
||||
-(void)setTarget:target;
|
||||
|
||||
-(void)attachColorList:(NSColorList *)colorList;
|
||||
-(void)detachColorList:(NSColorList *)colorList;
|
||||
|
||||
@end
|
||||
|
||||
@interface NSObject(NSColorPanel_responder)
|
||||
-(void)changeColor:sender;
|
||||
@end
|
||||
|
175
AppKit/NSColorPanel.m
Executable file
175
AppKit/NSColorPanel.m
Executable file
@ -0,0 +1,175 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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 - David Young <daver@geeks.org>
|
||||
#import <AppKit/AppKit.h>
|
||||
|
||||
#import <AppKit/NSColorPickerColorList.h>
|
||||
#import <AppKit/NSColorPickerSliders.h>
|
||||
|
||||
NSString *NSColorPanelColorDidChangeNotification = @"NSColorPanelColorDidChangeNotification";
|
||||
|
||||
@implementation NSColorPanel
|
||||
|
||||
static NSColorPanel *_colorPanel=nil;
|
||||
static int _pickerMask=0;
|
||||
|
||||
+(void)setColorPanel:(NSColorPanel *)colorPanel {
|
||||
[_colorPanel release];
|
||||
_colorPanel=[colorPanel retain];
|
||||
}
|
||||
|
||||
+(BOOL)sharedColorPanelExists { return _colorPanel != nil; }
|
||||
|
||||
+(NSColorPanel *)sharedColorPanel {
|
||||
if(_colorPanel==nil){
|
||||
if(![NSBundle loadNibNamed:@"NSColorPanel" owner:self])
|
||||
NSLog(@"Cannot load NSColorPanel.nib");
|
||||
|
||||
if(![_colorPanel setFrameUsingName:@"NSColorPanel"])
|
||||
[_colorPanel center];
|
||||
|
||||
[_colorPanel setFrameAutosaveName:@"NSColorPanel"];
|
||||
}
|
||||
|
||||
return _colorPanel;
|
||||
}
|
||||
|
||||
+ (void)setPickerMask:(int)mask
|
||||
{
|
||||
if (_colorPanel == nil) // only works if color panel is not yet created
|
||||
_pickerMask = mask;
|
||||
}
|
||||
|
||||
+ (void)setPickerMode:(int)mode { NSUnimplementedMethod(); }
|
||||
|
||||
+(BOOL)dragColor:(NSColor *)color withEvent:(NSEvent *)event fromView:(NSView *)view {
|
||||
NSPasteboard *pboard=[NSPasteboard pasteboardWithName:NSDragPboard];
|
||||
NSSize size=NSMakeSize(12,12);
|
||||
NSImage *image=[[[NSImage alloc] initWithSize:size] autorelease];
|
||||
|
||||
[image setCachedSeparately:YES];
|
||||
[image lockFocus];
|
||||
[color drawSwatchInRect:NSMakeRect(0,0,12,12)];
|
||||
[image unlockFocus];
|
||||
|
||||
[pboard declareTypes:[NSArray arrayWithObject:NSColorPboardType] owner:nil];
|
||||
[color writeToPasteboard:pboard];
|
||||
|
||||
[view dragImage:image at:NSMakePoint(0,0) offset:NSMakeSize(0,0) event:event
|
||||
pasteboard:pboard source:view slideBack:YES];
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)swapInNewView:sender
|
||||
{
|
||||
NSColorPicker *chosenColorPicker=[_colorPickers objectAtIndex:[sender selectedTag]];
|
||||
NSView *newView;
|
||||
|
||||
newView = [chosenColorPicker provideNewView:YES];
|
||||
|
||||
if (currentColorPickerView != newView) {
|
||||
[[sender selectedCell] setImage:[chosenColorPicker provideNewButtonImage]];
|
||||
|
||||
if (currentColorPickerView != nil)
|
||||
[newView setFrame:[currentColorPickerView frame]];
|
||||
else
|
||||
[newView setFrame:[colorPickerView bounds]];
|
||||
|
||||
[currentColorPickerView retain];
|
||||
[currentColorPickerView removeFromSuperview];
|
||||
|
||||
[colorPickerView addSubview:newView];
|
||||
// [splitView adjustSubviews];
|
||||
currentColorPickerView = [newView retain];
|
||||
}
|
||||
}
|
||||
|
||||
-(void)awakeFromNib
|
||||
{
|
||||
// time to load the color pickers. theoretically we should be searching all the /Library/ColorPickers out there, but...
|
||||
NSArray *colorPickersClassArray = [NSArray arrayWithObjects:
|
||||
[NSColorPickerSliders class],
|
||||
[NSColorPickerColorList class],
|
||||
nil];
|
||||
unsigned i,count=[colorPickersClassArray count];
|
||||
|
||||
[colorWell setBordered:NO];
|
||||
|
||||
_colorPickers=[[NSMutableArray alloc] init];
|
||||
[colorPickersMatrix renewRows:1 columns:count];
|
||||
|
||||
for(i=0;i<count;i++){
|
||||
Class colorPickerClass=[colorPickersClassArray objectAtIndex:i];
|
||||
NSColorPicker *newPicker=[[[colorPickerClass alloc] initWithPickerMask:_pickerMask colorPanel:self] autorelease];
|
||||
NSCell *cell=[colorPickersMatrix cellAtRow:0 column:i];
|
||||
|
||||
[_colorPickers addObject:newPicker];
|
||||
|
||||
[cell setImage:[newPicker provideNewButtonImage]];
|
||||
[cell setTag:i];
|
||||
[cell setTarget:self];
|
||||
[cell setAction:@selector(swapInNewView:)];
|
||||
}
|
||||
|
||||
[colorPickersMatrix selectCellAtRow:0 column:0];
|
||||
[self swapInNewView:colorPickersMatrix];
|
||||
}
|
||||
|
||||
-(NSColor *)color {
|
||||
return [colorWell color];
|
||||
}
|
||||
|
||||
- (float)alpha { return 1.0; }
|
||||
|
||||
- (int)mode {
|
||||
return _mode;
|
||||
}
|
||||
|
||||
-(BOOL)showsAlpha {
|
||||
return _showsAlpha;
|
||||
}
|
||||
|
||||
- (BOOL)isContinuous { return _continuous; }
|
||||
|
||||
-(NSView *)accessoryView {
|
||||
NSUnimplementedMethod();
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)setColorButtonClicked:sender
|
||||
{
|
||||
[NSApp sendAction:_action to:_target from:self];
|
||||
}
|
||||
|
||||
- (void)setColor:(NSColor *)color
|
||||
{
|
||||
[colorWell setColor:color];
|
||||
[self setColorButtonClicked:nil];
|
||||
|
||||
[[NSNotificationQueue defaultQueue] enqueueNotification:[NSNotification notificationWithName:NSColorPanelColorDidChangeNotification object:self] postingStyle:NSPostNow coalesceMask:NSNotificationCoalescingOnName forModes:nil];
|
||||
}
|
||||
|
||||
- (void)setMode:(int)mode { _mode = mode; }
|
||||
|
||||
-(void)setShowsAlpha:(BOOL)flag {_showsAlpha = flag; }
|
||||
|
||||
-(void)setContinuous:(BOOL)flag { _continuous = flag; }
|
||||
|
||||
-(void)setAccessoryView:(NSView *)view {
|
||||
NSUnimplementedMethod();
|
||||
}
|
||||
|
||||
- (void)setAction:(SEL)action { _action = action; }
|
||||
- (void)setTarget:target { [_target release]; _target = [target retain]; }
|
||||
|
||||
- (void)attachColorList:(NSColorList *)colorList { NSUnimplementedMethod(); }
|
||||
- (void)detachColorList:(NSColorList *)colorList { NSUnimplementedMethod(); }
|
||||
|
||||
@end
|
||||
|
25
AppKit/NSColorPanel.nib/classes.nib
generated
Normal file
25
AppKit/NSColorPanel.nib/classes.nib
generated
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
IBClasses = (
|
||||
{CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; },
|
||||
{
|
||||
ACTIONS = {setColorButtonClicked = id; };
|
||||
CLASS = NSColorPanel;
|
||||
LANGUAGE = ObjC;
|
||||
OUTLETS = {
|
||||
colorPickerView = id;
|
||||
colorPickersMatrix = id;
|
||||
colorWell = id;
|
||||
setColorButton = id;
|
||||
splitView = id;
|
||||
};
|
||||
SUPERCLASS = NSPanel;
|
||||
},
|
||||
{
|
||||
CLASS = Owner;
|
||||
LANGUAGE = ObjC;
|
||||
OUTLETS = {colorPanel = id; };
|
||||
SUPERCLASS = NSObject;
|
||||
}
|
||||
);
|
||||
IBVersion = 1;
|
||||
}
|
18
AppKit/NSColorPanel.nib/info.nib
generated
Normal file
18
AppKit/NSColorPanel.nib/info.nib
generated
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>IBDocumentLocation</key>
|
||||
<string>265 195 356 240 0 0 1680 1028 </string>
|
||||
<key>IBFramework Version</key>
|
||||
<string>446.1</string>
|
||||
<key>IBOpenObjects</key>
|
||||
<array>
|
||||
<integer>5</integer>
|
||||
</array>
|
||||
<key>IBSystem Version</key>
|
||||
<string>8L2127</string>
|
||||
<key>IBUsesTextArchiving</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
1470
AppKit/NSColorPanel.nib/keyedobjects.nib
generated
Normal file
1470
AppKit/NSColorPanel.nib/keyedobjects.nib
generated
Normal file
File diff suppressed because it is too large
Load Diff
BIN
AppKit/NSColorPanel.nib/objects.nib
generated
Normal file
BIN
AppKit/NSColorPanel.nib/objects.nib
generated
Normal file
Binary file not shown.
19
AppKit/NSColorPicker.subproj/NSBrowserCellColorList.h
Executable file
19
AppKit/NSColorPicker.subproj/NSBrowserCellColorList.h
Executable file
@ -0,0 +1,19 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/NSBrowserCell.h>
|
||||
|
||||
@interface NSBrowserCellColorList : NSBrowserCell
|
||||
{
|
||||
NSColor *_color;
|
||||
}
|
||||
|
||||
- (NSColor *)color;
|
||||
- (void)setColor:(NSColor *)color;
|
||||
|
||||
@end
|
51
AppKit/NSColorPicker.subproj/NSBrowserCellColorList.m
Executable file
51
AppKit/NSColorPicker.subproj/NSBrowserCellColorList.m
Executable file
@ -0,0 +1,51 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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 - David Young <daver@geeks.org>
|
||||
#import <AppKit/AppKit.h>
|
||||
#import <AppKit/NSBrowserCellColorList.h>
|
||||
#import <AppKit/NSStringDrawer.h>
|
||||
|
||||
@implementation NSBrowserCellColorList
|
||||
|
||||
- (NSColor *)color { return _color; }
|
||||
- (void)setColor:(NSColor *)color { [_color release]; _color = [color retain]; }
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[_color release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void)drawInteriorWithFrame:(NSRect)frame inView:(NSView *)control
|
||||
{
|
||||
NSAttributedString *title=[self attributedStringValue];
|
||||
NSRect colorRect = frame;
|
||||
NSSize titleSize=[title size];
|
||||
NSRect titleRect=frame;
|
||||
|
||||
colorRect.size.width = colorRect.size.height;
|
||||
|
||||
titleRect.origin.x += colorRect.size.width + 2;
|
||||
titleRect.origin.y += (titleRect.size.height-titleSize.height)/2;
|
||||
titleRect.size.height = titleSize.height;
|
||||
|
||||
titleRect.size.width -= (colorRect.size.width+2);
|
||||
|
||||
if([self isHighlighted] || [self state])
|
||||
[[NSColor selectedControlColor] set];
|
||||
else
|
||||
[[NSColor controlBackgroundColor] set]; // was whiteColor
|
||||
|
||||
NSRectFill(frame);
|
||||
|
||||
[_color drawSwatchInRect:colorRect];
|
||||
[title _clipAndDrawInRect:titleRect];
|
||||
}
|
||||
|
||||
@end
|
50
AppKit/NSColorPicker.subproj/NSColorPicker.h
Executable file
50
AppKit/NSColorPicker.subproj/NSColorPicker.h
Executable file
@ -0,0 +1,50 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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 <Foundation/Foundation.h>
|
||||
|
||||
@class NSColorPanel, NSImage, NSButtonCell, NSColorList, NSView, NSColor;
|
||||
|
||||
@protocol NSColorPickingDefault
|
||||
|
||||
-initWithPickerMask:(int)mask colorPanel:(NSColorPanel *)colorPanel;
|
||||
|
||||
-(void)setMode:(int)mode;
|
||||
-(void)attachColorList:(NSColorList *)colorList;
|
||||
-(void)detachColorList:(NSColorList *)colorList;
|
||||
|
||||
-(NSImage *)provideNewButtonImage;
|
||||
|
||||
-(void)insertNewButtonImage:(NSImage *)image in:(NSButtonCell *)buttonCell;
|
||||
|
||||
-(void)alphaControlAddedOrRemoved:sender;
|
||||
|
||||
-(void)viewSizeChanged:sender;
|
||||
|
||||
@end
|
||||
|
||||
@protocol NSColorPickingCustom
|
||||
|
||||
-(int)currentMode;
|
||||
-(BOOL)supportsMode:(int)mode;
|
||||
|
||||
-(void)setColor:(NSColor *)color;
|
||||
|
||||
-(NSView *)provideNewView:(BOOL)firstTime;
|
||||
|
||||
@end
|
||||
|
||||
@interface NSColorPicker : NSObject <NSColorPickingDefault, NSColorPickingCustom> {
|
||||
int _mask;
|
||||
NSColorPanel *_colorPanel;
|
||||
NSView *_subview;
|
||||
}
|
||||
|
||||
-(NSColorPanel *)colorPanel;
|
||||
|
||||
@end
|
95
AppKit/NSColorPicker.subproj/NSColorPicker.m
Executable file
95
AppKit/NSColorPicker.subproj/NSColorPicker.m
Executable file
@ -0,0 +1,95 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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 - David Young <daver@geeks.org>
|
||||
#import <AppKit/NSColorPicker.h>
|
||||
#import <AppKit/NSColorPanel.h>
|
||||
#import <AppKit/NSImage.h>
|
||||
#import <AppKit/NSButtonCell.h>
|
||||
#import <AppKit/NSNibLoading.h>
|
||||
|
||||
@implementation NSColorPicker
|
||||
|
||||
- initWithPickerMask:(int)mask colorPanel:(NSColorPanel *)colorPanel
|
||||
{
|
||||
if (![NSBundle loadNibNamed:[[self class] description] owner:self])
|
||||
NSLog(@"Couldn't load %@.nib", [[self class] description]);
|
||||
|
||||
_mask = mask;
|
||||
_colorPanel = [colorPanel retain];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[_colorPanel release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
// for IB
|
||||
- (void)setSubview:(NSView *)subview
|
||||
{
|
||||
_subview = [subview retain];
|
||||
}
|
||||
|
||||
-(void)setMode:(int)mode
|
||||
{
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
- (void)attachColorList:(NSColorList *)colorList
|
||||
{
|
||||
}
|
||||
|
||||
-(void)detachColorList:(NSColorList *)colorList
|
||||
{
|
||||
}
|
||||
|
||||
- (NSImage *)provideNewButtonImage
|
||||
{
|
||||
return [NSImage imageNamed:@"NSAlertPanelExclamation"];
|
||||
}
|
||||
|
||||
- (void)insertNewButtonImage:(NSImage *)image in:(NSButtonCell *)buttonCell
|
||||
{
|
||||
[buttonCell setImage:image];
|
||||
}
|
||||
|
||||
- (void)alphaControlAddedOrRemoved:sender
|
||||
{
|
||||
}
|
||||
|
||||
- (void)viewSizeChanged:sender
|
||||
{
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
- (int)currentMode
|
||||
{
|
||||
return [_colorPanel mode];
|
||||
}
|
||||
|
||||
- (BOOL)supportsMode:(int)mode
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void)setColor:(NSColor *)color
|
||||
{
|
||||
NSInvalidAbstractInvocation();
|
||||
}
|
||||
|
||||
- (NSView *)provideNewView:(BOOL)firstTime
|
||||
{
|
||||
return _subview;
|
||||
}
|
||||
|
||||
- (NSColorPanel *)colorPanel { return _colorPanel; }
|
||||
|
||||
@end
|
22
AppKit/NSColorPicker.subproj/NSColorPickerColorList.h
Executable file
22
AppKit/NSColorPicker.subproj/NSColorPickerColorList.h
Executable file
@ -0,0 +1,22 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/NSColorPicker.h>
|
||||
|
||||
@interface NSColorPickerColorList : NSColorPicker
|
||||
{
|
||||
NSBrowser *colorBrowser;
|
||||
NSPopUpButton *colorListPopUp;
|
||||
|
||||
NSColorList *_pickedColorList;
|
||||
}
|
||||
|
||||
- (void)colorListPopUpClicked:(id)sender;
|
||||
- (void)colorListBrowserClicked:(id)sender;
|
||||
|
||||
@end
|
69
AppKit/NSColorPicker.subproj/NSColorPickerColorList.m
Executable file
69
AppKit/NSColorPicker.subproj/NSColorPickerColorList.m
Executable file
@ -0,0 +1,69 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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 - David Young <daver@geeks.org>
|
||||
#import <AppKit/AppKit.h>
|
||||
#import <AppKit/NSColorPickerColorList.h>
|
||||
#import <AppKit/NSBrowserCellColorList.h>
|
||||
|
||||
@implementation NSColorPickerColorList
|
||||
|
||||
- (id)initWithPickerMask:(int)mask colorPanel:(NSColorPanel *)colorPanel
|
||||
{
|
||||
NSEnumerator *colorListsEnumerator = [[NSColorList availableColorLists] objectEnumerator];
|
||||
NSColorList *colorList;
|
||||
|
||||
[super initWithPickerMask:mask colorPanel:colorPanel];
|
||||
[colorBrowser setCellClass:[NSBrowserCellColorList class]];
|
||||
|
||||
[colorListPopUp removeAllItems];
|
||||
while (colorList = [colorListsEnumerator nextObject])
|
||||
[self attachColorList:colorList];
|
||||
|
||||
[self colorListPopUpClicked:colorListPopUp];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)attachColorList:(NSColorList *)colorList
|
||||
{
|
||||
[colorListPopUp addItemWithTitle:[colorList name]];
|
||||
}
|
||||
|
||||
- (void)colorListPopUpClicked:(id)sender
|
||||
{
|
||||
[_pickedColorList release];
|
||||
_pickedColorList = [[NSColorList colorListNamed:[[sender itemAtIndex:[sender indexOfSelectedItem]] title]] retain];
|
||||
|
||||
[colorBrowser reloadColumn:0];
|
||||
}
|
||||
|
||||
- (void)colorListBrowserClicked:(id)sender
|
||||
{
|
||||
[[NSColorPanel sharedColorPanel] setColor:[_pickedColorList colorWithKey:[[sender selectedCell] stringValue]]];
|
||||
}
|
||||
|
||||
- (int)browser:(NSBrowser *)sender numberOfRowsInColumn:(int)column
|
||||
{
|
||||
return [[_pickedColorList allKeys] count];
|
||||
}
|
||||
|
||||
- (NSImage *)provideNewButtonImage
|
||||
{
|
||||
return [NSImage imageNamed:@"NSColorPickerColorList"];
|
||||
}
|
||||
|
||||
- (void)browser:(NSBrowser *)sender willDisplayCell:(id)cell atRow:(int)row column:(int)column
|
||||
{
|
||||
[cell setStringValue:[[_pickedColorList allKeys] objectAtIndex:row]];
|
||||
[cell setLeaf:YES];
|
||||
[cell setLoaded:YES];
|
||||
[cell setColor:[_pickedColorList colorWithKey:[[_pickedColorList allKeys] objectAtIndex:row]]];
|
||||
}
|
||||
|
||||
@end
|
19
AppKit/NSColorPicker.subproj/NSColorPickerColorList.nib/classes.nib
generated
Normal file
19
AppKit/NSColorPicker.subproj/NSColorPickerColorList.nib/classes.nib
generated
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
IBClasses = (
|
||||
{CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; },
|
||||
{
|
||||
CLASS = NSColorPicker;
|
||||
LANGUAGE = ObjC;
|
||||
OUTLETS = {subview = id; };
|
||||
SUPERCLASS = NSObject;
|
||||
},
|
||||
{
|
||||
ACTIONS = {colorListBrowserClicked = id; colorListPopUpClicked = id; };
|
||||
CLASS = NSColorPickerColorList;
|
||||
LANGUAGE = ObjC;
|
||||
OUTLETS = {colorBrowser = id; colorListPopUp = id; };
|
||||
SUPERCLASS = NSColorPicker;
|
||||
}
|
||||
);
|
||||
IBVersion = 1;
|
||||
}
|
18
AppKit/NSColorPicker.subproj/NSColorPickerColorList.nib/info.nib
generated
Normal file
18
AppKit/NSColorPicker.subproj/NSColorPickerColorList.nib/info.nib
generated
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>IBDocumentLocation</key>
|
||||
<string>219 206 356 240 0 0 1600 1178 </string>
|
||||
<key>IBFramework Version</key>
|
||||
<string>446.1</string>
|
||||
<key>IBOpenObjects</key>
|
||||
<array>
|
||||
<integer>5</integer>
|
||||
</array>
|
||||
<key>IBSystem Version</key>
|
||||
<string>8H14</string>
|
||||
<key>IBUsesTextArchiving</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
1447
AppKit/NSColorPicker.subproj/NSColorPickerColorList.nib/keyedobjects.nib
generated
Normal file
1447
AppKit/NSColorPicker.subproj/NSColorPickerColorList.nib/keyedobjects.nib
generated
Normal file
File diff suppressed because it is too large
Load Diff
BIN
AppKit/NSColorPicker.subproj/NSColorPickerColorList.nib/objects.nib
generated
Normal file
BIN
AppKit/NSColorPicker.subproj/NSColorPickerColorList.nib/objects.nib
generated
Normal file
Binary file not shown.
BIN
AppKit/NSColorPicker.subproj/NSColorPickerColorList.tiff
Executable file
BIN
AppKit/NSColorPicker.subproj/NSColorPickerColorList.tiff
Executable file
Binary file not shown.
56
AppKit/NSColorPicker.subproj/NSColorPickerSliders.h
Executable file
56
AppKit/NSColorPicker.subproj/NSColorPickerSliders.h
Executable file
@ -0,0 +1,56 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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/NSColorPicker.h>
|
||||
|
||||
@interface NSColorPickerSliders : NSColorPicker
|
||||
{
|
||||
IBOutlet NSBox *sliderSubview;
|
||||
IBOutlet NSBox *greyscaleSubview;
|
||||
IBOutlet NSBox *rgbSubview;
|
||||
IBOutlet NSBox *cmykSubview;
|
||||
IBOutlet NSBox *hsbSubview;
|
||||
IBOutlet NSMatrix *matrix;
|
||||
IBOutlet NSView *currentView;
|
||||
IBOutlet NSSlider *greyscaleSlider;
|
||||
IBOutlet NSTextField *greyscaleTextField;
|
||||
IBOutlet NSMatrix *_grayscaleConstantsMatrix;
|
||||
|
||||
IBOutlet NSSlider *_redSlider;
|
||||
IBOutlet NSSlider *_greenSlider;
|
||||
IBOutlet NSSlider *_blueSlider;
|
||||
IBOutlet NSMatrix *rgbTextFieldMatrix;
|
||||
|
||||
IBOutlet NSSlider *_cyanSlider;
|
||||
IBOutlet NSSlider *_magentaSlider;
|
||||
IBOutlet NSSlider *_yellowSlider;
|
||||
IBOutlet NSSlider *_blackSlider;
|
||||
IBOutlet NSMatrix *cmykTextFieldMatrix;
|
||||
|
||||
IBOutlet NSSlider *_hueSlider;
|
||||
IBOutlet NSSlider *_saturationSlider;
|
||||
IBOutlet NSSlider *_brightnessSlider;
|
||||
|
||||
IBOutlet NSMatrix *hsbTextFieldMatrix;
|
||||
}
|
||||
|
||||
- (void)matrixClicked:(id)sender;
|
||||
|
||||
-(void)greyscaleDidChange:(id)sender;
|
||||
-(void)grayscaleConstant:sender;
|
||||
|
||||
-(void)rgbSliderChanged:sender;
|
||||
-(void)rgbTextChanged:sender;
|
||||
|
||||
-(void)cmykSliderChanged:sender;
|
||||
-(void)cmykTextChanged:sender;
|
||||
|
||||
-(void)hsbSliderChanged:sender;
|
||||
-(void)hsbTextChanged:sender;
|
||||
|
||||
@end
|
235
AppKit/NSColorPicker.subproj/NSColorPickerSliders.m
Executable file
235
AppKit/NSColorPicker.subproj/NSColorPickerSliders.m
Executable file
@ -0,0 +1,235 @@
|
||||
/* Copyright (c) 2006 Christopher J. W. Lloyd
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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 - David Young <daver@geeks.org>
|
||||
#import <AppKit/AppKit.h>
|
||||
|
||||
#import <AppKit/NSColorPickerSliders.h>
|
||||
|
||||
@implementation NSColorPickerSliders
|
||||
|
||||
- (id)initWithPickerMask:(int)mask colorPanel:(NSColorPanel *)colorPanel
|
||||
{
|
||||
[super initWithPickerMask:mask colorPanel:colorPanel];
|
||||
{
|
||||
NSSize size=[_grayscaleConstantsMatrix cellSize];
|
||||
int i;
|
||||
|
||||
size.width-=10;
|
||||
size.height-=10;
|
||||
|
||||
for(i=0;i<7;i++){
|
||||
NSImage *image=[[[NSImage alloc] initWithSize:size] autorelease];
|
||||
NSColor *color=[NSColor colorWithCalibratedWhite:i/6.0 alpha:1];
|
||||
|
||||
[image setCachedSeparately:YES];
|
||||
[image lockFocus];
|
||||
[color drawSwatchInRect:NSMakeRect(0,0,size.width,size.height)];
|
||||
[image unlockFocus];
|
||||
|
||||
[[_grayscaleConstantsMatrix cellAtRow:0 column:i] setImage:image];
|
||||
}
|
||||
}
|
||||
|
||||
[self matrixClicked:matrix];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)matrixClicked:(id)sender
|
||||
{
|
||||
NSView *newView = nil;
|
||||
NSColor *color = [[NSColorPanel sharedColorPanel] color];
|
||||
|
||||
switch ([[sender selectedCell] tag]) {
|
||||
case NSGrayModeColorPanel: {
|
||||
float gray, alpha;
|
||||
|
||||
color = [color colorUsingColorSpaceName:NSCalibratedWhiteColorSpace];
|
||||
[color getWhite:&gray alpha:&alpha];
|
||||
|
||||
[greyscaleSlider setIntValue:gray*100];
|
||||
[greyscaleTextField setIntValue:gray*100];
|
||||
newView = greyscaleSubview;
|
||||
break;
|
||||
}
|
||||
|
||||
case NSRGBModeColorPanel: {
|
||||
float red, green, blue, alpha;
|
||||
|
||||
color = [color colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
|
||||
[color getRed:&red green:&green blue:&blue alpha:&alpha];
|
||||
|
||||
[_redSlider setIntValue:red*255];
|
||||
[_greenSlider setIntValue:green*255];
|
||||
[_blueSlider setIntValue:blue*255];
|
||||
[[rgbTextFieldMatrix cellAtRow:0 column:0] setIntValue:red*255];
|
||||
[[rgbTextFieldMatrix cellAtRow:1 column:0] setIntValue:green*255];
|
||||
[[rgbTextFieldMatrix cellAtRow:2 column:0] setIntValue:blue*255];
|
||||
|
||||
newView = rgbSubview;
|
||||
break;
|
||||
}
|
||||
|
||||
case NSCMYKModeColorPanel: {
|
||||
float cyan, magenta, yellow, black, alpha;
|
||||
|
||||
color = [color colorUsingColorSpaceName:NSDeviceCMYKColorSpace];
|
||||
[color getCyan:&cyan magenta:&magenta yellow:&yellow black:&black alpha:&alpha];
|
||||
|
||||
[_cyanSlider setIntValue:cyan*100];
|
||||
[_magentaSlider setIntValue:magenta*100];
|
||||
[_yellowSlider setIntValue:yellow*100];
|
||||
[_blackSlider setIntValue:black*100];
|
||||
[[cmykTextFieldMatrix cellAtRow:0 column:0] setIntValue:cyan*100];
|
||||
[[cmykTextFieldMatrix cellAtRow:1 column:0] setIntValue:magenta*100];
|
||||
[[cmykTextFieldMatrix cellAtRow:2 column:0] setIntValue:yellow*100];
|
||||
[[cmykTextFieldMatrix cellAtRow:3 column:0] setIntValue:black*100];
|
||||
|
||||
newView = cmykSubview;
|
||||
break;
|
||||
}
|
||||
|
||||
case NSHSBModeColorPanel: {
|
||||
float hue, saturation, brightness, alpha;
|
||||
|
||||
color = [color colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
|
||||
[color getHue:&hue saturation:&saturation brightness:&brightness alpha:&alpha];
|
||||
|
||||
[_hueSlider setIntValue:hue*359];
|
||||
[_saturationSlider setIntValue:saturation*100];
|
||||
[_brightnessSlider setIntValue:brightness*100];
|
||||
[[hsbTextFieldMatrix cellAtRow:0 column:0] setIntValue:hue*359];
|
||||
[[hsbTextFieldMatrix cellAtRow:1 column:0] setIntValue:saturation*100];
|
||||
[[hsbTextFieldMatrix cellAtRow:2 column:0] setIntValue:brightness*100];
|
||||
|
||||
newView = hsbSubview;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentView != nil)
|
||||
[newView setFrame:[currentView frame]];
|
||||
|
||||
if (currentView != newView) {
|
||||
[currentView retain];
|
||||
[currentView removeFromSuperview];
|
||||
|
||||
[sliderSubview addSubview:newView];
|
||||
currentView = [newView retain];
|
||||
}
|
||||
|
||||
[[NSColorPanel sharedColorPanel] setColor:color];
|
||||
}
|
||||
|
||||
// doesn't matter who sends these actions, the sliders or the textfields.
|
||||
// n.b. some bounds checking should be performed, but it won't crash anything without it
|
||||
|
||||
- (void)greyscaleDidChange:(id)sender {
|
||||
int intValue=[sender intValue];
|
||||
|
||||
[greyscaleTextField setIntValue:intValue];
|
||||
[greyscaleSlider setIntValue:intValue];
|
||||
|
||||
[[NSColorPanel sharedColorPanel] setColor:[NSColor colorWithCalibratedWhite:intValue/100.0 alpha:1.0]];
|
||||
}
|
||||
|
||||
-(void)grayscaleConstant:sender {
|
||||
int i=[sender selectedColumn];
|
||||
float value=i/6.0;
|
||||
NSColor *color=[NSColor colorWithCalibratedWhite:value alpha:1];
|
||||
|
||||
[greyscaleTextField setIntValue:value*100];
|
||||
[greyscaleSlider setIntValue:value*100];
|
||||
|
||||
[[NSColorPanel sharedColorPanel] setColor:color];
|
||||
}
|
||||
|
||||
- (NSImage *)provideNewButtonImage
|
||||
{
|
||||
return [[matrix selectedCell] image];
|
||||
// return [NSImage imageNamed:@"NSColorPickerSlidersRGB"];
|
||||
}
|
||||
|
||||
-(void)_updateRed:red green:green blue:blue {
|
||||
[_redSlider setIntValue:[red intValue]];
|
||||
[_greenSlider setIntValue:[green intValue]];
|
||||
[_blueSlider setIntValue:[blue intValue]];
|
||||
|
||||
[[rgbTextFieldMatrix cellAtRow:0 column:0] setIntValue:[red intValue]];
|
||||
[[rgbTextFieldMatrix cellAtRow:1 column:0] setIntValue:[green intValue]];
|
||||
[[rgbTextFieldMatrix cellAtRow:2 column:0] setIntValue:[blue intValue]];
|
||||
|
||||
[[NSColorPanel sharedColorPanel] setColor:[NSColor colorWithCalibratedRed:[red floatValue]/255.0
|
||||
green:[green floatValue]/255.0
|
||||
blue:[blue floatValue]/255.0
|
||||
alpha:1.0]];
|
||||
}
|
||||
|
||||
-(void)rgbSliderChanged:sender {
|
||||
[self _updateRed:_redSlider green:_greenSlider blue:_blueSlider];
|
||||
}
|
||||
|
||||
-(void)rgbTextChanged:(id)sender {
|
||||
[self _updateRed:[rgbTextFieldMatrix cellAtRow:0 column:0] green:[rgbTextFieldMatrix cellAtRow:1 column:0] blue:[rgbTextFieldMatrix cellAtRow:2 column:0]];
|
||||
}
|
||||
|
||||
-(void)_updateCyan:cyan magenta:magenta yellow:yellow black:black {
|
||||
[[cmykTextFieldMatrix cellAtRow:0 column:0] setIntValue:[cyan intValue]];
|
||||
[[cmykTextFieldMatrix cellAtRow:1 column:0] setIntValue:[magenta intValue]];
|
||||
[[cmykTextFieldMatrix cellAtRow:2 column:0] setIntValue:[yellow intValue]];
|
||||
[[cmykTextFieldMatrix cellAtRow:3 column:0] setIntValue:[black intValue]];
|
||||
|
||||
[_cyanSlider setIntValue:[cyan intValue]];
|
||||
[_magentaSlider setIntValue:[magenta intValue]];
|
||||
[_yellowSlider setIntValue:[yellow intValue]];
|
||||
[_blackSlider setIntValue:[black intValue]];
|
||||
|
||||
[[NSColorPanel sharedColorPanel] setColor:[NSColor colorWithDeviceCyan:[cyan floatValue]/100.0
|
||||
magenta:[magenta floatValue]/100.0
|
||||
yellow:[yellow floatValue]/100.0
|
||||
black:[black floatValue]/100.0
|
||||
alpha:1.0]];
|
||||
}
|
||||
|
||||
-(void)cmykSliderChanged:sender {
|
||||
[self _updateCyan:_cyanSlider magenta:_magentaSlider yellow:_yellowSlider black:_blackSlider];
|
||||
}
|
||||
|
||||
-(void)cmykTextChanged:sender {
|
||||
[self _updateCyan:[cmykTextFieldMatrix cellAtRow:0 column:0] magenta:[cmykTextFieldMatrix cellAtRow:1 column:0] yellow:[cmykTextFieldMatrix cellAtRow:2 column:0] black:[cmykTextFieldMatrix cellAtRow:3 column:0]];
|
||||
}
|
||||
|
||||
-(void)_updateHue:hue saturation:saturation brightness:brightness {
|
||||
[[hsbTextFieldMatrix cellAtRow:0 column:0] setIntValue:[hue intValue]];
|
||||
[[hsbTextFieldMatrix cellAtRow:1 column:0] setIntValue:[saturation intValue]];
|
||||
[[hsbTextFieldMatrix cellAtRow:2 column:0] setIntValue:[brightness intValue]];
|
||||
|
||||
[_hueSlider setIntValue:[hue intValue]];
|
||||
[_saturationSlider setIntValue:[saturation intValue]];
|
||||
[_brightnessSlider setIntValue:[brightness intValue]];
|
||||
|
||||
[[NSColorPanel sharedColorPanel] setColor:[NSColor colorWithCalibratedHue:[hue floatValue]/359.0
|
||||
saturation:[saturation floatValue]/100.0
|
||||
brightness:[brightness floatValue]/100.0
|
||||
alpha:1.0]];
|
||||
}
|
||||
|
||||
-(void)hsbSliderChanged:sender {
|
||||
[self _updateHue:_hueSlider saturation:_saturationSlider brightness:_brightnessSlider];
|
||||
}
|
||||
|
||||
-(void)hsbTextChanged:sender {
|
||||
[self _updateHue:[hsbTextFieldMatrix cellAtRow:0 column:0] saturation:[hsbTextFieldMatrix cellAtRow:1 column:0] brightness:[hsbTextFieldMatrix cellAtRow:2 column:0]];
|
||||
}
|
||||
|
||||
|
||||
@end
|
53
AppKit/NSColorPicker.subproj/NSColorPickerSliders.nib/classes.nib
generated
Normal file
53
AppKit/NSColorPicker.subproj/NSColorPickerSliders.nib/classes.nib
generated
Normal file
@ -0,0 +1,53 @@
|
||||
{
|
||||
IBClasses = (
|
||||
{CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; },
|
||||
{
|
||||
CLASS = NSColorPicker;
|
||||
LANGUAGE = ObjC;
|
||||
OUTLETS = {subview = id; };
|
||||
SUPERCLASS = NSObject;
|
||||
},
|
||||
{
|
||||
ACTIONS = {
|
||||
cmykSliderChanged = id;
|
||||
cmykTextChanged = id;
|
||||
grayscaleConstant = id;
|
||||
greyscaleDidChange = id;
|
||||
hsbSliderChanged = id;
|
||||
hsbTextChanged = id;
|
||||
matrixClicked = id;
|
||||
rgbSliderChanged = id;
|
||||
rgbTextChanged = id;
|
||||
};
|
||||
CLASS = NSColorPickerSliders;
|
||||
LANGUAGE = ObjC;
|
||||
OUTLETS = {
|
||||
"_blackSlider" = id;
|
||||
"_blueSlider" = id;
|
||||
"_brightnessSlider" = id;
|
||||
"_cyanSlider" = id;
|
||||
"_grayscaleConstantsMatrix" = id;
|
||||
"_greenSlider" = id;
|
||||
"_hueSlider" = id;
|
||||
"_magentaSlider" = id;
|
||||
"_redSlider" = id;
|
||||
"_saturationSlider" = id;
|
||||
"_yellowSlider" = id;
|
||||
cmykSubview = id;
|
||||
cmykTextFieldMatrix = id;
|
||||
currentView = id;
|
||||
greyscaleSlider = id;
|
||||
greyscaleSubview = id;
|
||||
greyscaleTextField = id;
|
||||
hsbSubview = id;
|
||||
hsbTextFieldMatrix = id;
|
||||
matrix = id;
|
||||
rgbSubview = id;
|
||||
rgbTextFieldMatrix = id;
|
||||
sliderSubview = id;
|
||||
};
|
||||
SUPERCLASS = NSColorPicker;
|
||||
}
|
||||
);
|
||||
IBVersion = 1;
|
||||
}
|
14
AppKit/NSColorPicker.subproj/NSColorPickerSliders.nib/info.nib
generated
Normal file
14
AppKit/NSColorPicker.subproj/NSColorPickerSliders.nib/info.nib
generated
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>IBDocumentLocation</key>
|
||||
<string>189 180 356 240 0 0 1600 1178 </string>
|
||||
<key>IBFramework Version</key>
|
||||
<string>446.1</string>
|
||||
<key>IBSystem Version</key>
|
||||
<string>8H14</string>
|
||||
<key>IBUsesTextArchiving</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
8492
AppKit/NSColorPicker.subproj/NSColorPickerSliders.nib/keyedobjects.nib
generated
Normal file
8492
AppKit/NSColorPicker.subproj/NSColorPickerSliders.nib/keyedobjects.nib
generated
Normal file
File diff suppressed because it is too large
Load Diff
BIN
AppKit/NSColorPicker.subproj/NSColorPickerSliders.nib/objects.nib
generated
Normal file
BIN
AppKit/NSColorPicker.subproj/NSColorPickerSliders.nib/objects.nib
generated
Normal file
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user