diff --git a/src/MacVim/CTGradient.h b/src/MacVim/CTGradient.h deleted file mode 100644 index 68f3a4b106..0000000000 --- a/src/MacVim/CTGradient.h +++ /dev/null @@ -1,73 +0,0 @@ -// -// CTGradient.h -// -// Created by Chad Weider on 2/14/07. -// Writtin by Chad Weider. -// -// Released into public domain on 4/10/08. -// -// Version: 1.8 - -#import - -typedef struct _CTGradientElement - { - float red, green, blue, alpha; - float position; - - struct _CTGradientElement *nextElement; - } CTGradientElement; - -typedef enum _CTBlendingMode - { - CTLinearBlendingMode, - CTChromaticBlendingMode, - CTInverseChromaticBlendingMode - } CTGradientBlendingMode; - - -@interface CTGradient : NSObject - { - CTGradientElement* elementList; - CTGradientBlendingMode blendingMode; - - CGFunctionRef gradientFunction; - } - -+ (id)gradientWithBeginningColor:(NSColor *)begin endingColor:(NSColor *)end; - -+ (id)aquaSelectedGradient; -+ (id)aquaNormalGradient; -+ (id)aquaPressedGradient; - -+ (id)unifiedSelectedGradient; -+ (id)unifiedNormalGradient; -+ (id)unifiedPressedGradient; -+ (id)unifiedDarkGradient; - -+ (id)sourceListSelectedGradient; -+ (id)sourceListUnselectedGradient; - -+ (id)rainbowGradient; -+ (id)hydrogenSpectrumGradient; - -- (CTGradient *)gradientWithAlphaComponent:(float)alpha; - -- (CTGradient *)addColorStop:(NSColor *)color atPosition:(float)position; //positions given relative to [0,1] -- (CTGradient *)removeColorStopAtIndex:(unsigned)index; -- (CTGradient *)removeColorStopAtPosition:(float)position; - -- (CTGradientBlendingMode)blendingMode; -- (NSColor *)colorStopAtIndex:(unsigned)index; -- (NSColor *)colorAtPosition:(float)position; - - -- (void)drawSwatchInRect:(NSRect)rect; -- (void)fillRect:(NSRect)rect angle:(float)angle; //fills rect with axial gradient - // angle in degrees -- (void)radialFillRect:(NSRect)rect; //fills rect with radial gradient - // gradient from center outwards -- (void)fillBezierPath:(NSBezierPath *)path angle:(float)angle; -- (void)radialFillBezierPath:(NSBezierPath *)path; - -@end diff --git a/src/MacVim/CTGradient.m b/src/MacVim/CTGradient.m deleted file mode 100644 index 4056fcf60e..0000000000 --- a/src/MacVim/CTGradient.m +++ /dev/null @@ -1,1271 +0,0 @@ -// -// CTGradient.m -// -// Created by Chad Weider on 2/14/07. -// Writtin by Chad Weider. -// -// Released into public domain on 4/10/08. -// -// Version: 1.8 -#ifdef MM_ENABLE_PLUGINS - -#import "CTGradient.h" - -@interface CTGradient (Private) -- (void)_commonInit; -- (void)setBlendingMode:(CTGradientBlendingMode)mode; -- (void)addElement:(CTGradientElement*)newElement; - -- (CTGradientElement *)elementAtIndex:(unsigned)index; - -- (CTGradientElement)removeElementAtIndex:(unsigned)index; -- (CTGradientElement)removeElementAtPosition:(float)position; -@end - -//C Fuctions for color blending -static void linearEvaluation (void *info, const float *in, float *out); -static void chromaticEvaluation(void *info, const float *in, float *out); -static void inverseChromaticEvaluation(void *info, const float *in, float *out); -static void transformRGB_HSV(float *components); -static void transformHSV_RGB(float *components); -static void resolveHSV(float *color1, float *color2); - - -@implementation CTGradient -/////////////////////////////////////Initialization Type Stuff -- (id)init - { - self = [super init]; - - if (self != nil) - { - [self _commonInit]; - [self setBlendingMode:CTLinearBlendingMode]; - } - return self; - } - -- (void)_commonInit - { - elementList = nil; - } - -- (void)dealloc - { - CGFunctionRelease(gradientFunction); - - CTGradientElement *elementToRemove = elementList; - while(elementList != nil) - { - elementToRemove = elementList; - elementList = elementList->nextElement; - free(elementToRemove); - } - - [super dealloc]; - } - -- (id)copyWithZone:(NSZone *)zone - { - CTGradient *copy = [[[self class] allocWithZone:zone] init]; - - //now just copy my elementlist - CTGradientElement *currentElement = elementList; - while(currentElement != nil) - { - [copy addElement:currentElement]; - currentElement = currentElement->nextElement; - } - - [copy setBlendingMode:blendingMode]; - - return copy; - } - -- (void)encodeWithCoder:(NSCoder *)coder - { - if([coder allowsKeyedCoding]) - { - unsigned count = 0; - CTGradientElement *currentElement = elementList; - while(currentElement != nil) - { - [coder encodeValueOfObjCType:@encode(float) at:&(currentElement->red)]; - [coder encodeValueOfObjCType:@encode(float) at:&(currentElement->green)]; - [coder encodeValueOfObjCType:@encode(float) at:&(currentElement->blue)]; - [coder encodeValueOfObjCType:@encode(float) at:&(currentElement->alpha)]; - [coder encodeValueOfObjCType:@encode(float) at:&(currentElement->position)]; - - count++; - currentElement = currentElement->nextElement; - } - [coder encodeInt:count forKey:@"CTGradientElementCount"]; - [coder encodeInt:blendingMode forKey:@"CTGradientBlendingMode"]; - } - else - [NSException raise:NSInvalidArchiveOperationException format:@"Only supports NSKeyedArchiver coders"]; - } - -- (id)initWithCoder:(NSCoder *)coder - { - [self _commonInit]; - - [self setBlendingMode:[coder decodeIntForKey:@"CTGradientBlendingMode"]]; - unsigned count = [coder decodeIntForKey:@"CTGradientElementCount"]; - - while(count != 0) - { - CTGradientElement newElement; - - [coder decodeValueOfObjCType:@encode(float) at:&(newElement.red)]; - [coder decodeValueOfObjCType:@encode(float) at:&(newElement.green)]; - [coder decodeValueOfObjCType:@encode(float) at:&(newElement.blue)]; - [coder decodeValueOfObjCType:@encode(float) at:&(newElement.alpha)]; - [coder decodeValueOfObjCType:@encode(float) at:&(newElement.position)]; - - count--; - [self addElement:&newElement]; - } - return self; - } -#pragma mark - - - - -#pragma mark Creation -+ (id)gradientWithBeginningColor:(NSColor *)begin endingColor:(NSColor *)end - { - id newInstance = [[[self class] alloc] init]; - - CTGradientElement color1; - CTGradientElement color2; - - [[begin colorUsingColorSpaceName:NSCalibratedRGBColorSpace] getRed:&color1.red - green:&color1.green - blue:&color1.blue - alpha:&color1.alpha]; - - [[end colorUsingColorSpaceName:NSCalibratedRGBColorSpace] getRed:&color2.red - green:&color2.green - blue:&color2.blue - alpha:&color2.alpha]; - color1.position = 0; - color2.position = 1; - - [newInstance addElement:&color1]; - [newInstance addElement:&color2]; - - return [newInstance autorelease]; - } - -+ (id)aquaSelectedGradient - { - id newInstance = [[[self class] alloc] init]; - - CTGradientElement color1; - color1.red = 0.58; - color1.green = 0.86; - color1.blue = 0.98; - color1.alpha = 1.00; - color1.position = 0; - - CTGradientElement color2; - color2.red = 0.42; - color2.green = 0.68; - color2.blue = 0.90; - color2.alpha = 1.00; - color2.position = 11.5/23; - - CTGradientElement color3; - color3.red = 0.64; - color3.green = 0.80; - color3.blue = 0.94; - color3.alpha = 1.00; - color3.position = 11.5/23; - - CTGradientElement color4; - color4.red = 0.56; - color4.green = 0.70; - color4.blue = 0.90; - color4.alpha = 1.00; - color4.position = 1; - - [newInstance addElement:&color1]; - [newInstance addElement:&color2]; - [newInstance addElement:&color3]; - [newInstance addElement:&color4]; - - return [newInstance autorelease]; - } - -+ (id)aquaNormalGradient - { - id newInstance = [[[self class] alloc] init]; - - CTGradientElement color1; - color1.red = color1.green = color1.blue = 0.95; - color1.alpha = 1.00; - color1.position = 0; - - CTGradientElement color2; - color2.red = color2.green = color2.blue = 0.83; - color2.alpha = 1.00; - color2.position = 11.5/23; - - CTGradientElement color3; - color3.red = color3.green = color3.blue = 0.95; - color3.alpha = 1.00; - color3.position = 11.5/23; - - CTGradientElement color4; - color4.red = color4.green = color4.blue = 0.92; - color4.alpha = 1.00; - color4.position = 1; - - [newInstance addElement:&color1]; - [newInstance addElement:&color2]; - [newInstance addElement:&color3]; - [newInstance addElement:&color4]; - - return [newInstance autorelease]; - } - -+ (id)aquaPressedGradient - { - id newInstance = [[[self class] alloc] init]; - - CTGradientElement color1; - color1.red = color1.green = color1.blue = 0.80; - color1.alpha = 1.00; - color1.position = 0; - - CTGradientElement color2; - color2.red = color2.green = color2.blue = 0.64; - color2.alpha = 1.00; - color2.position = 11.5/23; - - CTGradientElement color3; - color3.red = color3.green = color3.blue = 0.80; - color3.alpha = 1.00; - color3.position = 11.5/23; - - CTGradientElement color4; - color4.red = color4.green = color4.blue = 0.77; - color4.alpha = 1.00; - color4.position = 1; - - [newInstance addElement:&color1]; - [newInstance addElement:&color2]; - [newInstance addElement:&color3]; - [newInstance addElement:&color4]; - - return [newInstance autorelease]; - } - -+ (id)unifiedSelectedGradient - { - id newInstance = [[[self class] alloc] init]; - - CTGradientElement color1; - color1.red = color1.green = color1.blue = 0.85; - color1.alpha = 1.00; - color1.position = 0; - - CTGradientElement color2; - color2.red = color2.green = color2.blue = 0.95; - color2.alpha = 1.00; - color2.position = 1; - - [newInstance addElement:&color1]; - [newInstance addElement:&color2]; - - return [newInstance autorelease]; - } - -+ (id)unifiedNormalGradient - { - id newInstance = [[[self class] alloc] init]; - - CTGradientElement color1; - color1.red = color1.green = color1.blue = 0.75; - color1.alpha = 1.00; - color1.position = 0; - - CTGradientElement color2; - color2.red = color2.green = color2.blue = 0.90; - color2.alpha = 1.00; - color2.position = 1; - - [newInstance addElement:&color1]; - [newInstance addElement:&color2]; - - return [newInstance autorelease]; - } - -+ (id)unifiedPressedGradient - { - id newInstance = [[[self class] alloc] init]; - - CTGradientElement color1; - color1.red = color1.green = color1.blue = 0.60; - color1.alpha = 1.00; - color1.position = 0; - - CTGradientElement color2; - color2.red = color2.green = color2.blue = 0.75; - color2.alpha = 1.00; - color2.position = 1; - - [newInstance addElement:&color1]; - [newInstance addElement:&color2]; - - return [newInstance autorelease]; - } - -+ (id)unifiedDarkGradient - { - id newInstance = [[[self class] alloc] init]; - - CTGradientElement color1; - color1.red = color1.green = color1.blue = 0.68; - color1.alpha = 1.00; - color1.position = 0; - - CTGradientElement color2; - color2.red = color2.green = color2.blue = 0.83; - color2.alpha = 1.00; - color2.position = 1; - - [newInstance addElement:&color1]; - [newInstance addElement:&color2]; - - return [newInstance autorelease]; - } - -+ (id)sourceListSelectedGradient - { - id newInstance = [[[self class] alloc] init]; - - CTGradientElement color1; - color1.red = 0.06; - color1.green = 0.37; - color1.blue = 0.85; - color1.alpha = 1.00; - color1.position = 0; - - CTGradientElement color2; - color2.red = 0.30; - color2.green = 0.60; - color2.blue = 0.92; - color2.alpha = 1.00; - color2.position = 1; - - [newInstance addElement:&color1]; - [newInstance addElement:&color2]; - - return [newInstance autorelease]; - } - -+ (id)sourceListUnselectedGradient - { - id newInstance = [[[self class] alloc] init]; - - CTGradientElement color1; - color1.red = 0.43; - color1.green = 0.43; - color1.blue = 0.43; - color1.alpha = 1.00; - color1.position = 0; - - CTGradientElement color2; - color2.red = 0.60; - color2.green = 0.60; - color2.blue = 0.60; - color2.alpha = 1.00; - color2.position = 1; - - [newInstance addElement:&color1]; - [newInstance addElement:&color2]; - - return [newInstance autorelease]; - } - -+ (id)rainbowGradient - { - id newInstance = [[[self class] alloc] init]; - - CTGradientElement color1; - color1.red = 1.00; - color1.green = 0.00; - color1.blue = 0.00; - color1.alpha = 1.00; - color1.position = 0.0; - - CTGradientElement color2; - color2.red = 0.54; - color2.green = 0.00; - color2.blue = 1.00; - color2.alpha = 1.00; - color2.position = 1.0; - - [newInstance addElement:&color1]; - [newInstance addElement:&color2]; - - [newInstance setBlendingMode:CTChromaticBlendingMode]; - - return [newInstance autorelease]; - } - -+ (id)hydrogenSpectrumGradient - { - id newInstance = [[[self class] alloc] init]; - - struct {float hue; float position; float width;} colorBands[4]; - - colorBands[0].hue = 22; - colorBands[0].position = .145; - colorBands[0].width = .01; - - colorBands[1].hue = 200; - colorBands[1].position = .71; - colorBands[1].width = .008; - - colorBands[2].hue = 253; - colorBands[2].position = .885; - colorBands[2].width = .005; - - colorBands[3].hue = 275; - colorBands[3].position = .965; - colorBands[3].width = .003; - - int i; - ///////////////////////////// - for(i = 0; i < 4; i++) - { - float color[4]; - color[0] = colorBands[i].hue - 180*colorBands[i].width; - color[1] = 1; - color[2] = 0.001; - color[3] = 1; - transformHSV_RGB(color); - CTGradientElement fadeIn; - fadeIn.red = color[0]; - fadeIn.green = color[1]; - fadeIn.blue = color[2]; - fadeIn.alpha = color[3]; - fadeIn.position = colorBands[i].position - colorBands[i].width; - - - color[0] = colorBands[i].hue; - color[1] = 1; - color[2] = 1; - color[3] = 1; - transformHSV_RGB(color); - CTGradientElement band; - band.red = color[0]; - band.green = color[1]; - band.blue = color[2]; - band.alpha = color[3]; - band.position = colorBands[i].position; - - color[0] = colorBands[i].hue + 180*colorBands[i].width; - color[1] = 1; - color[2] = 0.001; - color[3] = 1; - transformHSV_RGB(color); - CTGradientElement fadeOut; - fadeOut.red = color[0]; - fadeOut.green = color[1]; - fadeOut.blue = color[2]; - fadeOut.alpha = color[3]; - fadeOut.position = colorBands[i].position + colorBands[i].width; - - - [newInstance addElement:&fadeIn]; - [newInstance addElement:&band]; - [newInstance addElement:&fadeOut]; - } - - [newInstance setBlendingMode:CTChromaticBlendingMode]; - - return [newInstance autorelease]; - } - -#pragma mark - - - - -#pragma mark Modification -- (CTGradient *)gradientWithAlphaComponent:(float)alpha - { - id newInstance = [[[self class] alloc] init]; - - CTGradientElement *curElement = elementList; - CTGradientElement tempElement; - - while(curElement != nil) - { - tempElement = *curElement; - tempElement.alpha = alpha; - [newInstance addElement:&tempElement]; - - curElement = curElement->nextElement; - } - - return [newInstance autorelease]; - } - -- (CTGradient *)gradientWithBlendingMode:(CTGradientBlendingMode)mode - { - CTGradient *newGradient = [self copy]; - - [newGradient setBlendingMode:mode]; - - return [newGradient autorelease]; - } - - -//Adds a color stop with at in elementList -//(if two elements are at the same position then added imediatly after the one that was there already) -- (CTGradient *)addColorStop:(NSColor *)color atPosition:(float)position - { - CTGradient *newGradient = [self copy]; - CTGradientElement newGradientElement; - - //put the components of color into the newGradientElement - must make sure it is a RGB color (not Gray or CMYK) - [[color colorUsingColorSpaceName:NSCalibratedRGBColorSpace] getRed:&newGradientElement.red - green:&newGradientElement.green - blue:&newGradientElement.blue - alpha:&newGradientElement.alpha]; - newGradientElement.position = position; - - //Pass it off to addElement to take care of adding it to the elementList - [newGradient addElement:&newGradientElement]; - - return [newGradient autorelease]; - } - - -//Removes the color stop at from elementList -- (CTGradient *)removeColorStopAtPosition:(float)position - { - CTGradient *newGradient = [self copy]; - CTGradientElement removedElement = [newGradient removeElementAtPosition:position]; - - if(isnan(removedElement.position)) - [NSException raise:NSRangeException format:@"-[%@ removeColorStopAtPosition:]: no such colorStop at position (%f)", [self class], position]; - - return [newGradient autorelease]; - } - -- (CTGradient *)removeColorStopAtIndex:(unsigned)index - { - CTGradient *newGradient = [self copy]; - CTGradientElement removedElement = [newGradient removeElementAtIndex:index]; - - if(isnan(removedElement.position)) - [NSException raise:NSRangeException format:@"-[%@ removeColorStopAtIndex:]: index (%i) beyond bounds", [self class], index]; - - return [newGradient autorelease]; - } -#pragma mark - - - - -#pragma mark Information -- (CTGradientBlendingMode)blendingMode - { - return blendingMode; - } - -//Returns color at in gradient -- (NSColor *)colorStopAtIndex:(unsigned)index - { - CTGradientElement *element = [self elementAtIndex:index]; - - if(element != nil) - return [NSColor colorWithCalibratedRed:element->red - green:element->green - blue:element->blue - alpha:element->alpha]; - - [NSException raise:NSRangeException format:@"-[%@ removeColorStopAtIndex:]: index (%i) beyond bounds", [self class], index]; - - return nil; - } - -- (NSColor *)colorAtPosition:(float)position - { - float components[4]; - - switch(blendingMode) - { - case CTLinearBlendingMode: - linearEvaluation(&elementList, &position, components); break; - case CTChromaticBlendingMode: - chromaticEvaluation(&elementList, &position, components); break; - case CTInverseChromaticBlendingMode: - inverseChromaticEvaluation(&elementList, &position, components); break; - } - - - return [NSColor colorWithCalibratedRed:components[0]/components[3] //undo premultiplication that CG requires - green:components[1]/components[3] - blue:components[2]/components[3] - alpha:components[3]]; - } -#pragma mark - - - - -#pragma mark Drawing -- (void)drawSwatchInRect:(NSRect)rect - { - [self fillRect:rect angle:45]; - } - -- (void)fillRect:(NSRect)rect angle:(float)angle - { - //First Calculate where the beginning and ending points should be - CGPoint startPoint; - CGPoint endPoint; - - if(angle == 0) //screw the calculations - we know the answer - { - startPoint = CGPointMake(NSMinX(rect), NSMinY(rect)); //right of rect - endPoint = CGPointMake(NSMaxX(rect), NSMinY(rect)); //left of rect - } - else if(angle == 90) //same as above - { - startPoint = CGPointMake(NSMinX(rect), NSMinY(rect)); //bottom of rect - endPoint = CGPointMake(NSMinX(rect), NSMaxY(rect)); //top of rect - } - else //ok, we'll do the calculations now - { - float x,y; - float sina, cosa, tana; - - float length; - float deltax, - deltay; - - float rangle = angle * pi/180; //convert the angle to radians - - if(fabsf(tan(rangle))<=1) //for range [-45,45], [135,225] - { - x = NSWidth(rect); - y = NSHeight(rect); - - sina = sin(rangle); - cosa = cos(rangle); - tana = tan(rangle); - - length = x/fabsf(cosa)+(y-x*fabsf(tana))*fabsf(sina); - - deltax = length*cosa/2; - deltay = length*sina/2; - } - else //for range [45,135], [225,315] - { - x = NSHeight(rect); - y = NSWidth(rect); - - sina = sin(rangle - 90*pi/180); - cosa = cos(rangle - 90*pi/180); - tana = tan(rangle - 90*pi/180); - - length = x/fabsf(cosa)+(y-x*fabsf(tana))*fabsf(sina); - - deltax =-length*sina/2; - deltay = length*cosa/2; - } - - startPoint = CGPointMake(NSMidX(rect)-deltax, NSMidY(rect)-deltay); - endPoint = CGPointMake(NSMidX(rect)+deltax, NSMidY(rect)+deltay); - } - - //Calls to CoreGraphics - CGContextRef currentContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]; - CGContextSaveGState(currentContext); - #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4 - CGColorSpaceRef colorspace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); - #else - CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB(); - #endif - CGShadingRef myCGShading = CGShadingCreateAxial(colorspace, startPoint, endPoint, gradientFunction, false, false); - - CGContextClipToRect (currentContext, *(CGRect *)&rect); //This is where the action happens - CGContextDrawShading(currentContext, myCGShading); - - CGShadingRelease(myCGShading); - CGColorSpaceRelease(colorspace ); - CGContextRestoreGState(currentContext); - } - -- (void)radialFillRect:(NSRect)rect - { - CGPoint startPoint, endPoint; - float startRadius, endRadius; - float scalex, scaley, transx, transy; - - startPoint = endPoint = CGPointMake(NSMidX(rect), NSMidY(rect)); - - startRadius = -1; - if(NSHeight(rect)>NSWidth(rect)) - { - scalex = NSWidth(rect)/NSHeight(rect); - transx = (NSHeight(rect)-NSWidth(rect))/2; - scaley = 1; - transy = 1; - endRadius = NSHeight(rect)/2; - } - else - { - scalex = 1; - transx = 1; - scaley = NSHeight(rect)/NSWidth(rect); - transy = (NSWidth(rect)-NSHeight(rect))/2; - endRadius = NSWidth(rect)/2; - } - - //Calls to CoreGraphics - CGContextRef currentContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]; - CGContextSaveGState(currentContext); - #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 - CGColorSpaceRef colorspace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); - #else - CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB(); - #endif - CGShadingRef myCGShading = CGShadingCreateRadial(colorspace, startPoint, startRadius, endPoint, endRadius, gradientFunction, true, true); - - CGContextClipToRect (currentContext, *(CGRect *)&rect); - CGContextScaleCTM (currentContext, scalex, scaley); - CGContextTranslateCTM(currentContext, transx, transy); - CGContextDrawShading (currentContext, myCGShading); //This is where the action happens - - CGShadingRelease(myCGShading); - CGColorSpaceRelease(colorspace); - CGContextRestoreGState(currentContext); - } - -- (void)fillBezierPath:(NSBezierPath *)path angle:(float)angle - { - NSGraphicsContext *currentContext = [NSGraphicsContext currentContext]; - [currentContext saveGraphicsState]; - NSAffineTransform *transform = [[NSAffineTransform alloc] init]; - - [transform rotateByDegrees:-angle]; - [path transformUsingAffineTransform:transform]; - [transform invert]; - [transform concat]; - - [path addClip]; - [self fillRect:[path bounds] angle:0]; - [path transformUsingAffineTransform:transform]; - [transform release]; - [currentContext restoreGraphicsState]; - } -- (void)radialFillBezierPath:(NSBezierPath *)path - { - NSGraphicsContext *currentContext = [NSGraphicsContext currentContext]; - [currentContext saveGraphicsState]; - [path addClip]; - [self radialFillRect:[path bounds]]; - [currentContext restoreGraphicsState]; - } -#pragma mark - - - - -#pragma mark Private Methods -- (void)setBlendingMode:(CTGradientBlendingMode)mode; - { - blendingMode = mode; - - //Choose what blending function to use - void *evaluationFunction; - switch(blendingMode) - { - case CTLinearBlendingMode: - evaluationFunction = &linearEvaluation; break; - case CTChromaticBlendingMode: - evaluationFunction = &chromaticEvaluation; break; - case CTInverseChromaticBlendingMode: - evaluationFunction = &inverseChromaticEvaluation; break; - } - - //replace the current CoreGraphics Function with new one - if(gradientFunction != NULL) - CGFunctionRelease(gradientFunction); - - CGFunctionCallbacks evaluationCallbackInfo = {0 , evaluationFunction, NULL}; //Version, evaluator function, cleanup function - - static const float input_value_range [2] = { 0, 1 }; //range for the evaluator input - static const float output_value_ranges [8] = { 0, 1, 0, 1, 0, 1, 0, 1 }; //ranges for the evaluator output (4 returned values) - - gradientFunction = CGFunctionCreate(&elementList, //the two transition colors - 1, input_value_range , //number of inputs (just fraction of progression) - 4, output_value_ranges, //number of outputs (4 - RGBa) - &evaluationCallbackInfo); //info for using the evaluator function - } - -- (void)addElement:(CTGradientElement *)newElement - { - if(elementList == nil || newElement->position < elementList->position) //inserting at beginning of list - { - CTGradientElement *tmpNext = elementList; - elementList = malloc(sizeof(CTGradientElement)); - *elementList = *newElement; - elementList->nextElement = tmpNext; - } - else //inserting somewhere inside list - { - CTGradientElement *curElement = elementList; - - while(curElement->nextElement != nil && !((curElement->position <= newElement->position) && (newElement->position < curElement->nextElement->position))) - { - curElement = curElement->nextElement; - } - - CTGradientElement *tmpNext = curElement->nextElement; - curElement->nextElement = malloc(sizeof(CTGradientElement)); - *(curElement->nextElement) = *newElement; - curElement->nextElement->nextElement = tmpNext; - } - } - -- (CTGradientElement)removeElementAtIndex:(unsigned)index - { - CTGradientElement removedElement; - - if(elementList != nil) - { - if(index == 0) - { - CTGradientElement *tmpNext = elementList; - elementList = elementList->nextElement; - - removedElement = *tmpNext; - free(tmpNext); - - return removedElement; - } - - unsigned count = 1; //we want to start one ahead - CTGradientElement *currentElement = elementList; - while(currentElement->nextElement != nil) - { - if(count == index) - { - CTGradientElement *tmpNext = currentElement->nextElement; - currentElement->nextElement = currentElement->nextElement->nextElement; - - removedElement = *tmpNext; - free(tmpNext); - - return removedElement; - } - - count++; - currentElement = currentElement->nextElement; - } - } - - //element is not found, return empty element - removedElement.red = 0.0; - removedElement.green = 0.0; - removedElement.blue = 0.0; - removedElement.alpha = 0.0; - removedElement.position = NAN; - removedElement.nextElement = nil; - - return removedElement; - } - -- (CTGradientElement)removeElementAtPosition:(float)position - { - CTGradientElement removedElement; - - if(elementList != nil) - { - if(elementList->position == position) - { - CTGradientElement *tmpNext = elementList; - elementList = elementList->nextElement; - - removedElement = *tmpNext; - free(tmpNext); - - return removedElement; - } - else - { - CTGradientElement *curElement = elementList; - while(curElement->nextElement != nil) - { - if(curElement->nextElement->position == position) - { - CTGradientElement *tmpNext = curElement->nextElement; - curElement->nextElement = curElement->nextElement->nextElement; - - removedElement = *tmpNext; - free(tmpNext); - - return removedElement; - } - } - } - } - - //element is not found, return empty element - removedElement.red = 0.0; - removedElement.green = 0.0; - removedElement.blue = 0.0; - removedElement.alpha = 0.0; - removedElement.position = NAN; - removedElement.nextElement = nil; - - return removedElement; - } - - -- (CTGradientElement *)elementAtIndex:(unsigned)index; - { - unsigned count = 0; - CTGradientElement *currentElement = elementList; - - while(currentElement != nil) - { - if(count == index) - return currentElement; - - count++; - currentElement = currentElement->nextElement; - } - - return nil; - } -#pragma mark - - - - -#pragma mark Core Graphics -//////////////////////////////////////Blending Functions///////////////////////////////////// -void linearEvaluation (void *info, const float *in, float *out) - { - float position = *in; - - if(*(CTGradientElement **)info == nil) //if elementList is empty return clear color - { - out[0] = out[1] = out[2] = out[3] = 1; - return; - } - - //This grabs the first two colors in the sequence - CTGradientElement *color1 = *(CTGradientElement **)info; - CTGradientElement *color2 = color1->nextElement; - - //make sure first color and second color are on other sides of position - while(color2 != nil && color2->position < position) - { - color1 = color2; - color2 = color1->nextElement; - } - //if we don't have another color then make next color the same color - if(color2 == nil) - { - color2 = color1; - } - - //----------FailSafe settings---------- - //color1->red = 1; color2->red = 0; - //color1->green = 1; color2->green = 0; - //color1->blue = 1; color2->blue = 0; - //color1->alpha = 1; color2->alpha = 1; - //color1->position = .5; - //color2->position = .5; - //------------------------------------- - - if(position <= color1->position) //Make all below color color1's position equal to color1 - { - out[0] = color1->red; - out[1] = color1->green; - out[2] = color1->blue; - out[3] = color1->alpha; - } - else if (position >= color2->position) //Make all above color color2's position equal to color2 - { - out[0] = color2->red; - out[1] = color2->green; - out[2] = color2->blue; - out[3] = color2->alpha; - } - else //Interpolate color at postions between color1 and color1 - { - //adjust position so that it goes from 0 to 1 in the range from color 1 & 2's position - position = (position-color1->position)/(color2->position - color1->position); - - out[0] = (color2->red - color1->red )*position + color1->red; - out[1] = (color2->green - color1->green)*position + color1->green; - out[2] = (color2->blue - color1->blue )*position + color1->blue; - out[3] = (color2->alpha - color1->alpha)*position + color1->alpha; - } - - //Premultiply the color by the alpha. - out[0] *= out[3]; - out[1] *= out[3]; - out[2] *= out[3]; - } - - - - -//Chromatic Evaluation - -// This blends colors by their Hue, Saturation, and Value(Brightness) right now I just -// transform the RGB values stored in the CTGradientElements to HSB, in the future I may -// streamline it to avoid transforming in and out of HSB colorspace *for later* -// -// For the chromatic blend we shift the hue of color1 to meet the hue of color2. To do -// this we will add to the hue's angle (if we subtract we'll be doing the inverse -// chromatic...scroll down more for that). All we need to do is keep adding to the hue -// until we wrap around the colorwheel and get to color2. -void chromaticEvaluation(void *info, const float *in, float *out) - { - float position = *in; - - if(*(CTGradientElement **)info == nil) //if elementList is empty return clear color - { - out[0] = out[1] = out[2] = out[3] = 1; - return; - } - - //This grabs the first two colors in the sequence - CTGradientElement *color1 = *(CTGradientElement **)info; - CTGradientElement *color2 = color1->nextElement; - - float c1[4]; - float c2[4]; - - //make sure first color and second color are on other sides of position - while(color2 != nil && color2->position < position) - { - color1 = color2; - color2 = color1->nextElement; - } - //if we don't have another color then make next color the same color - if(color2 == nil) - { - color2 = color1; - } - - - c1[0] = color1->red; - c1[1] = color1->green; - c1[2] = color1->blue; - c1[3] = color1->alpha; - - c2[0] = color2->red; - c2[1] = color2->green; - c2[2] = color2->blue; - c2[3] = color2->alpha; - - transformRGB_HSV(c1); - transformRGB_HSV(c2); - resolveHSV(c1,c2); - - if(c1[0] > c2[0]) //if color1's hue is higher than color2's hue then - c2[0] += 360; // we need to move c2 one revolution around the wheel - - - if(position <= color1->position) //Make all below color color1's position equal to color1 - { - out[0] = c1[0]; - out[1] = c1[1]; - out[2] = c1[2]; - out[3] = c1[3]; - } - else if (position >= color2->position) //Make all above color color2's position equal to color2 - { - out[0] = c2[0]; - out[1] = c2[1]; - out[2] = c2[2]; - out[3] = c2[3]; - } - else //Interpolate color at postions between color1 and color1 - { - //adjust position so that it goes from 0 to 1 in the range from color 1 & 2's position - position = (position-color1->position)/(color2->position - color1->position); - - out[0] = (c2[0] - c1[0])*position + c1[0]; - out[1] = (c2[1] - c1[1])*position + c1[1]; - out[2] = (c2[2] - c1[2])*position + c1[2]; - out[3] = (c2[3] - c1[3])*position + c1[3]; - } - - transformHSV_RGB(out); - - //Premultiply the color by the alpha. - out[0] *= out[3]; - out[1] *= out[3]; - out[2] *= out[3]; - } - - - -//Inverse Chromatic Evaluation - -// Inverse Chromatic is about the same story as Chromatic Blend, but here the Hue -// is strictly decreasing, that is we need to get from color1 to color2 by decreasing -// the 'angle' (i.e. 90¼ -> 180¼ would be done by subtracting 270¼ and getting -180¼... -// which is equivalent to 180¼ mod 360¼ -void inverseChromaticEvaluation(void *info, const float *in, float *out) - { - float position = *in; - - if(*(CTGradientElement **)info == nil) //if elementList is empty return clear color - { - out[0] = out[1] = out[2] = out[3] = 1; - return; - } - - //This grabs the first two colors in the sequence - CTGradientElement *color1 = *(CTGradientElement **)info; - CTGradientElement *color2 = color1->nextElement; - - float c1[4]; - float c2[4]; - - //make sure first color and second color are on other sides of position - while(color2 != nil && color2->position < position) - { - color1 = color2; - color2 = color1->nextElement; - } - //if we don't have another color then make next color the same color - if(color2 == nil) - { - color2 = color1; - } - - c1[0] = color1->red; - c1[1] = color1->green; - c1[2] = color1->blue; - c1[3] = color1->alpha; - - c2[0] = color2->red; - c2[1] = color2->green; - c2[2] = color2->blue; - c2[3] = color2->alpha; - - transformRGB_HSV(c1); - transformRGB_HSV(c2); - resolveHSV(c1,c2); - - if(c1[0] < c2[0]) //if color1's hue is higher than color2's hue then - c1[0] += 360; // we need to move c2 one revolution back on the wheel - - - if(position <= color1->position) //Make all below color color1's position equal to color1 - { - out[0] = c1[0]; - out[1] = c1[1]; - out[2] = c1[2]; - out[3] = c1[3]; - } - else if (position >= color2->position) //Make all above color color2's position equal to color2 - { - out[0] = c2[0]; - out[1] = c2[1]; - out[2] = c2[2]; - out[3] = c2[3]; - } - else //Interpolate color at postions between color1 and color1 - { - //adjust position so that it goes from 0 to 1 in the range from color 1 & 2's position - position = (position-color1->position)/(color2->position - color1->position); - - out[0] = (c2[0] - c1[0])*position + c1[0]; - out[1] = (c2[1] - c1[1])*position + c1[1]; - out[2] = (c2[2] - c1[2])*position + c1[2]; - out[3] = (c2[3] - c1[3])*position + c1[3]; - } - - transformHSV_RGB(out); - - //Premultiply the color by the alpha. - out[0] *= out[3]; - out[1] *= out[3]; - out[2] *= out[3]; - } - - -void transformRGB_HSV(float *components) //H,S,B -> R,G,B - { - float H, S, V; - float R = components[0], - G = components[1], - B = components[2]; - - float MAX = R > G ? (R > B ? R : B) : (G > B ? G : B), - MIN = R < G ? (R < B ? R : B) : (G < B ? G : B); - - if(MAX == MIN) - H = NAN; - else if(MAX == R) - if(G >= B) - H = 60*(G-B)/(MAX-MIN)+0; - else - H = 60*(G-B)/(MAX-MIN)+360; - else if(MAX == G) - H = 60*(B-R)/(MAX-MIN)+120; - else if(MAX == B) - H = 60*(R-G)/(MAX-MIN)+240; - - S = MAX == 0 ? 0 : 1 - MIN/MAX; - V = MAX; - - components[0] = H; - components[1] = S; - components[2] = V; - } - -void transformHSV_RGB(float *components) //H,S,B -> R,G,B - { - float R, G, B; - float H = fmodf(components[0],359), //map to [0,360) - S = components[1], - V = components[2]; - - int Hi = (int)floorf(H/60.) % 6; - float f = H/60-Hi, - p = V*(1-S), - q = V*(1-f*S), - t = V*(1-(1-f)*S); - - switch (Hi) - { - case 0: R=V;G=t;B=p; break; - case 1: R=q;G=V;B=p; break; - case 2: R=p;G=V;B=t; break; - case 3: R=p;G=q;B=V; break; - case 4: R=t;G=p;B=V; break; - case 5: R=V;G=p;B=q; break; - } - - components[0] = R; - components[1] = G; - components[2] = B; - } - -void resolveHSV(float *color1, float *color2) //H value may be undefined (i.e. graycale color) - { // we want to fill it with a sensible value - if(isnan(color1[0]) && isnan(color2[0])) - color1[0] = color2[0] = 0; - else if(isnan(color1[0])) - color1[0] = color2[0]; - else if(isnan(color2[0])) - color2[0] = color1[0]; - } - -@end - -#endif // MM_ENABLE_PLUGINS diff --git a/src/MacVim/MMAppController.h b/src/MacVim/MMAppController.h index 1e7870399b..fa507c89d5 100644 --- a/src/MacVim/MMAppController.h +++ b/src/MacVim/MMAppController.h @@ -35,10 +35,6 @@ #if (MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_4) FSEventStreamRef fsEventStream; #endif - -#ifdef MM_ENABLE_PLUGINS - NSMenuItem *plugInMenuItem; -#endif } + (MMAppController *)sharedInstance; @@ -51,12 +47,6 @@ - (NSArray *)filterOpenFiles:(NSArray *)filenames; - (BOOL)openFiles:(NSArray *)filenames withArguments:(NSDictionary *)args; - -#ifdef MM_ENABLE_PLUGINS -- (void)addItemToPlugInMenu:(NSMenuItem *)item; -- (void)removeItemFromPlugInMenu:(NSMenuItem *)item; -#endif - - (IBAction)newWindow:(id)sender; - (IBAction)newWindowAndActivate:(id)sender; - (IBAction)fileOpen:(id)sender; diff --git a/src/MacVim/MMAppController.m b/src/MacVim/MMAppController.m index 2d93266484..4bb582b0bd 100644 --- a/src/MacVim/MMAppController.m +++ b/src/MacVim/MMAppController.m @@ -42,11 +42,6 @@ #import "MMVimController.h" #import "MMWindowController.h" #import "Miscellaneous.h" - -#ifdef MM_ENABLE_PLUGINS -#import "MMPlugInManager.h" -#endif - #import #import @@ -142,11 +137,6 @@ typedef struct toCommandLine:(NSArray **)cmdline; - (NSString *)workingDirectoryForArguments:(NSDictionary *)args; - (NSScreen *)screenContainingPoint:(NSPoint)pt; - -#ifdef MM_ENABLE_PLUGINS -- (void)removePlugInMenu; -- (void)addPlugInMenuToMenu:(NSMenu *)mainMenu; -#endif @end @@ -216,9 +206,6 @@ fsEventCallback(ConstFSEventStreamRef streamRef, @"", MMLoginShellCommandKey, @"", MMLoginShellArgumentKey, [NSNumber numberWithBool:YES], MMDialogsTrackPwdKey, -#ifdef MM_ENABLE_PLUGINS - [NSNumber numberWithBool:YES], MMShowLeftPlugInContainerKey, -#endif [NSNumber numberWithInt:3], MMOpenLayoutKey, [NSNumber numberWithBool:NO], MMVerticalSplitKey, [NSNumber numberWithInt:0], MMPreloadCacheSizeKey, @@ -253,17 +240,6 @@ fsEventCallback(ConstFSEventStreamRef streamRef, pidArguments = [NSMutableDictionary new]; inputQueues = [NSMutableDictionary new]; -#ifdef MM_ENABLE_PLUGINS - NSString *plugInTitle = NSLocalizedString(@"Plug-In", - @"Plug-In menu title"); - plugInMenuItem = [[NSMenuItem alloc] initWithTitle:plugInTitle - action:NULL - keyEquivalent:@""]; - NSMenu *submenu = [[NSMenu alloc] initWithTitle:plugInTitle]; - [plugInMenuItem setSubmenu:submenu]; - [submenu release]; -#endif - // NOTE: Do not use the default connection since the Logitech Control // Center (LCC) input manager steals and this would cause MacVim to // never open any windows. (This is a bug in LCC but since they are @@ -298,9 +274,6 @@ fsEventCallback(ConstFSEventStreamRef streamRef, [openSelectionString release]; openSelectionString = nil; [recentFilesMenuItem release]; recentFilesMenuItem = nil; [defaultMainMenu release]; defaultMainMenu = nil; -#ifdef MM_ENABLE_PLUGINS - [plugInMenuItem release]; plugInMenuItem = nil; -#endif [appMenuItemTemplate release]; appMenuItemTemplate = nil; [super dealloc]; @@ -399,9 +372,6 @@ fsEventCallback(ConstFSEventStreamRef streamRef, - (void)applicationDidFinishLaunching:(NSNotification *)notification { [NSApp setServicesProvider:self]; -#ifdef MM_ENABLE_PLUGINS - [[MMPlugInManager sharedManager] loadAllPlugIns]; -#endif if ([self maxPreloadCacheSize] > 0) { [self scheduleVimControllerPreloadAfterDelay:2]; @@ -633,10 +603,6 @@ fsEventCallback(ConstFSEventStreamRef streamRef, [self stopWatchingVimDir]; -#ifdef MM_ENABLE_PLUGINS - [[MMPlugInManager sharedManager] unloadAllPlugIns]; -#endif - #if MM_HANDLE_XCODE_MOD_EVENT [[NSAppleEventManager sharedAppleEventManager] removeEventHandlerForEventClass:'KAHL' @@ -889,12 +855,6 @@ fsEventCallback(ConstFSEventStreamRef streamRef, } } [NSApp setWindowsMenu:windowsMenu]; - -#ifdef MM_ENABLE_PLUGINS - // Move plugin menu from old to new main menu. - [self removePlugInMenu]; - [self addPlugInMenuToMenu:mainMenu]; -#endif } - (NSArray *)filterOpenFiles:(NSArray *)filenames @@ -1052,24 +1012,6 @@ fsEventCallback(ConstFSEventStreamRef streamRef, return openOk; } -#ifdef MM_ENABLE_PLUGINS -- (void)addItemToPlugInMenu:(NSMenuItem *)item -{ - NSMenu *menu = [plugInMenuItem submenu]; - [menu addItem:item]; - if ([menu numberOfItems] == 1) - [self addPlugInMenuToMenu:[NSApp mainMenu]]; -} - -- (void)removeItemFromPlugInMenu:(NSMenuItem *)item -{ - NSMenu *menu = [plugInMenuItem submenu]; - [menu removeItem:item]; - if ([menu numberOfItems] == 0) - [self removePlugInMenu]; -} -#endif - - (IBAction)newWindow:(id)sender { ASLogDebug(@"Open new window"); @@ -1810,29 +1752,6 @@ fsEventCallback(ConstFSEventStreamRef streamRef, return dict; } -#ifdef MM_ENABLE_PLUGINS -- (void)removePlugInMenu -{ - if ([plugInMenuItem menu]) - [[plugInMenuItem menu] removeItem:plugInMenuItem]; -} - -- (void)addPlugInMenuToMenu:(NSMenu *)mainMenu -{ - NSMenu *windowsMenu = [mainMenu findWindowsMenu]; - - if ([[plugInMenuItem submenu] numberOfItems] > 0) { - int idx = windowsMenu ? [mainMenu indexOfItemWithSubmenu:windowsMenu] - : -1; - if (idx > 0) { - [mainMenu insertItem:plugInMenuItem atIndex:idx]; - } else { - [mainMenu addItem:plugInMenuItem]; - } - } -} -#endif - - (void)scheduleVimControllerPreloadAfterDelay:(NSTimeInterval)delay { [self performSelector:@selector(preloadVimController:) diff --git a/src/MacVim/MMPlugInManager.h b/src/MacVim/MMPlugInManager.h deleted file mode 100644 index 03008556cc..0000000000 --- a/src/MacVim/MMPlugInManager.h +++ /dev/null @@ -1,31 +0,0 @@ -/* vi:set ts=8 sts=4 sw=4 ft=objc: - * - * VIM - Vi IMproved by Bram Moolenaar - * MacVim GUI port by Bjorn Winckler - * - * Do ":help uganda" in Vim to read copying and usage conditions. - * Do ":help credits" in Vim to see a list of people who contributed. - * See README.txt for an overview of the Vim source code. - */ - -#import -#import "MMVimController.h" - - -@interface MMPlugInManager : NSObject { - - NSMutableArray *plugInClasses; -} - -- (NSArray *)plugInClasses; - -// Find and load any plugins -- (void)loadAllPlugIns; - -// release instances of loaded plugins -- (void)unloadAllPlugIns; - -// Return singleton instance of MMPluginManager -+ (MMPlugInManager *)sharedManager; - -@end diff --git a/src/MacVim/MMPlugInManager.m b/src/MacVim/MMPlugInManager.m deleted file mode 100644 index 9707d364e4..0000000000 --- a/src/MacVim/MMPlugInManager.m +++ /dev/null @@ -1,151 +0,0 @@ -/* vi:set ts=8 sts=4 sw=4 ft=objc: - * - * VIM - Vi IMproved by Bram Moolenaar - * MacVim GUI port by Bjorn Winckler - * - * Do ":help uganda" in Vim to read copying and usage conditions. - * Do ":help credits" in Vim to see a list of people who contributed. - * See README.txt for an overview of the Vim source code. - */ - -/* - * MMPlugInManager - * - * This class is responsible for finding MacVim plugins at startup, loading - * them, and keeping track of them. - * - * Author: Matt Tolton - */ - -#import "MacVim.h" - -#ifdef MM_ENABLE_PLUGINS - -#import "MMPlugInManager.h" -#import "PlugInInterface.h" -#import "PlugInImpl.h" - -@implementation MMPlugInManager - -static NSString *ext = @"mmplugin"; - -static NSString *appSupportSubpath = @"Application Support/MacVim/PlugIns"; - -static MMPlugInManager *plugInManager = nil; - -+ (MMPlugInManager*)sharedManager -{ - if (!plugInManager) - plugInManager = [[MMPlugInManager alloc] init]; - - return plugInManager; -} - -- (id)init -{ - if ((self = [super init]) == nil) return nil; - plugInClasses = [[NSMutableArray alloc] init]; - return self; -} - -- (void)dealloc -{ - ASLogDebug(@""); - - [plugInClasses release]; plugInClasses = nil; - [super dealloc]; -} - -- (NSArray *)plugInClasses; -{ - return plugInClasses; -} - -- (NSMutableArray *)allBundles -{ - NSArray *librarySearchPaths; - NSEnumerator *searchPathEnum; - NSString *currPath; - NSMutableArray *bundleSearchPaths = [NSMutableArray array]; - NSMutableArray *allBundles = [NSMutableArray array]; - - librarySearchPaths = NSSearchPathForDirectoriesInDomains( - NSLibraryDirectory, NSAllDomainsMask - NSSystemDomainMask, YES); - - searchPathEnum = [librarySearchPaths objectEnumerator]; - while(currPath = [searchPathEnum nextObject]) { - [bundleSearchPaths addObject: - [currPath stringByAppendingPathComponent:appSupportSubpath]]; - } - - [bundleSearchPaths addObject: - [[NSBundle mainBundle] builtInPlugInsPath]]; - - searchPathEnum = [bundleSearchPaths objectEnumerator]; - while(currPath = [searchPathEnum nextObject]) { - NSDirectoryEnumerator *bundleEnum; - NSString *currBundlePath; - bundleEnum = [[NSFileManager defaultManager] - enumeratorAtPath:currPath]; - if(bundleEnum) { - while(currBundlePath = [bundleEnum nextObject]) { - if([[currBundlePath pathExtension] isEqualToString:ext]) { - [allBundles addObject:[currPath - stringByAppendingPathComponent:currBundlePath]]; - } - } - } - } - - return allBundles; -} - -- (BOOL)plugInClassIsValid:(Class)class -{ - return [class conformsToProtocol:@protocol(PlugInProtocol)]; -} - -- (void)loadAllPlugIns -{ - NSMutableArray *bundlePaths; - NSEnumerator *pathEnum; - NSString *currPath; - NSBundle *currBundle; - Class currPrincipalClass; - - bundlePaths = [NSMutableArray array]; - - [bundlePaths addObjectsFromArray:[self allBundles]]; - - pathEnum = [bundlePaths objectEnumerator]; - while(currPath = [pathEnum nextObject]) { - currBundle = [NSBundle bundleWithPath:currPath]; - if(currBundle) { - currPrincipalClass = [currBundle principalClass]; - if(currPrincipalClass && [self plugInClassIsValid:currPrincipalClass]) { - if ([currPrincipalClass initializePlugIn: - [MMPlugInAppMediator sharedAppMediator]]) { - ASLogInfo(@"Plug-in initialized: %@", currPath); - [plugInClasses addObject:currPrincipalClass]; - } else { - ASLogErr(@"Plug-in failed to initialize: %@", currPath); - } - } else { - ASLogErr(@"Plug-in did not conform to protocol: %@", currPath); - } - } - } -} - -- (void)unloadAllPlugIns -{ - int i, count = [plugInClasses count]; - for (i = 0; i < count; i++) - [[plugInClasses objectAtIndex:i] terminatePlugIn]; - - [plugInClasses removeAllObjects]; -} - -@end - -#endif diff --git a/src/MacVim/MMVimController.h b/src/MacVim/MMVimController.h index 982d2d2ae8..b9fbaac0c5 100644 --- a/src/MacVim/MMVimController.h +++ b/src/MacVim/MMVimController.h @@ -10,10 +10,6 @@ #import "MacVim.h" -#ifdef MM_ENABLE_PLUGINS -#import "PlugInImpl.h" -#endif - @class MMWindowController; @@ -36,9 +32,6 @@ int pid; NSString *serverName; NSDictionary *vimState; -#ifdef MM_ENABLE_PLUGINS - MMPlugInInstanceMediator *instanceMediator; -#endif BOOL isPreloading; NSDate *creationDate; } @@ -70,7 +63,4 @@ - (id)evaluateVimExpressionCocoa:(NSString *)expr errorString:(NSString **)errstr; - (void)processInputQueue:(NSArray *)queue; -#ifdef MM_ENABLE_PLUGINS -- (MMPlugInInstanceMediator *)instanceMediator; -#endif @end diff --git a/src/MacVim/MMVimController.m b/src/MacVim/MMVimController.m index d300cd7d90..a6810382e3 100644 --- a/src/MacVim/MMVimController.m +++ b/src/MacVim/MMVimController.m @@ -34,9 +34,6 @@ #import "MMWindowController.h" #import "Miscellaneous.h" -#ifdef MM_ENABLE_PLUGINS -#import "MMPlugInManager.h" -#endif static NSString *MMDefaultToolbarImageName = @"Attention"; static int MMAlertTextFieldHeight = 22; @@ -150,11 +147,6 @@ static BOOL isUnsafeMessage(int msgid); [mainMenu addItem:appMenuItem]; -#ifdef MM_ENABLE_PLUGINS - instanceMediator = [[MMPlugInInstanceMediator alloc] - initWithVimController:self]; -#endif - isInitialized = YES; return self; @@ -166,10 +158,6 @@ static BOOL isUnsafeMessage(int msgid); isInitialized = NO; -#ifdef MM_ENABLE_PLUGINS - [instanceMediator release]; instanceMediator = nil; -#endif - [serverName release]; serverName = nil; [backendProxy release]; backendProxy = nil; @@ -195,13 +183,6 @@ static BOOL isUnsafeMessage(int msgid); return windowController; } -#ifdef MM_ENABLE_PLUGINS -- (MMPlugInInstanceMediator *)instanceMediator -{ - return instanceMediator; -} -#endif - - (NSDictionary *)vimState { return vimState; diff --git a/src/MacVim/MacVim.h b/src/MacVim/MacVim.h index 0158a60088..306864a258 100644 --- a/src/MacVim/MacVim.h +++ b/src/MacVim/MacVim.h @@ -12,13 +12,6 @@ #import -// -// Uncomment to enable support for MacVim plugins (not to be confused with Vim -// plugins!). -// -//#define MM_ENABLE_PLUGINS - - // Taken from /usr/include/AvailabilityMacros.h #ifndef MAC_OS_X_VERSION_10_4 # define MAC_OS_X_VERSION_10_4 1040 diff --git a/src/MacVim/MacVim.xcodeproj/project.pbxproj b/src/MacVim/MacVim.xcodeproj/project.pbxproj index fc0a4a39e5..827a4c6e36 100644 --- a/src/MacVim/MacVim.xcodeproj/project.pbxproj +++ b/src/MacVim/MacVim.xcodeproj/project.pbxproj @@ -73,13 +73,6 @@ 8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; }; 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; }; B59228A611F7572F00E7F584 /* MacVim.sdef in Resources */ = {isa = PBXBuildFile; fileRef = B59228A511F7572F00E7F584 /* MacVim.sdef */; }; - BD476E300DAAD74400F08A5C /* RBSplitSubview.m in Sources */ = {isa = PBXBuildFile; fileRef = BD476E2C0DAAD74400F08A5C /* RBSplitSubview.m */; }; - BD476E310DAAD74400F08A5C /* RBSplitView.m in Sources */ = {isa = PBXBuildFile; fileRef = BD476E2E0DAAD74400F08A5C /* RBSplitView.m */; }; - BD943D530DA3050B00A02D9B /* PlugInImpl.m in Sources */ = {isa = PBXBuildFile; fileRef = BD943D520DA3050B00A02D9B /* PlugInImpl.m */; }; - BD9DF0A00DB2BA020025C97C /* PlugInView.nib in Resources */ = {isa = PBXBuildFile; fileRef = BD9DF09F0DB2BA020025C97C /* PlugInView.nib */; }; - BD9DF0B00DB41E780025C97C /* PlugInGUI.m in Sources */ = {isa = PBXBuildFile; fileRef = BD9DF0AF0DB41E780025C97C /* PlugInGUI.m */; }; - BD9DF0FB0DB48C860025C97C /* CTGradient.m in Sources */ = {isa = PBXBuildFile; fileRef = BD9DF0FA0DB48C860025C97C /* CTGradient.m */; }; - BDA8B1120D9F8A8500B3511A /* MMPlugInManager.m in Sources */ = {isa = PBXBuildFile; fileRef = BDA8B1110D9F8A8500B3511A /* MMPlugInManager.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -226,21 +219,6 @@ 8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; 8D1107320486CEB800E47090 /* MacVim.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MacVim.app; sourceTree = BUILT_PRODUCTS_DIR; }; B59228A511F7572F00E7F584 /* MacVim.sdef */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.sdef; path = MacVim.sdef; sourceTree = ""; }; - BD476E2B0DAAD74400F08A5C /* RBSplitSubview.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RBSplitSubview.h; sourceTree = ""; }; - BD476E2C0DAAD74400F08A5C /* RBSplitSubview.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RBSplitSubview.m; sourceTree = ""; }; - BD476E2D0DAAD74400F08A5C /* RBSplitView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RBSplitView.h; sourceTree = ""; }; - BD476E2E0DAAD74400F08A5C /* RBSplitView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RBSplitView.m; sourceTree = ""; }; - BD476E2F0DAAD74400F08A5C /* RBSplitViewPrivateDefines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RBSplitViewPrivateDefines.h; sourceTree = ""; }; - BD943D310DA2EA2500A02D9B /* PlugInInterface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlugInInterface.h; sourceTree = ""; }; - BD943D510DA3050B00A02D9B /* PlugInImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlugInImpl.h; sourceTree = ""; }; - BD943D520DA3050B00A02D9B /* PlugInImpl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PlugInImpl.m; sourceTree = ""; }; - BD9DF09F0DB2BA020025C97C /* PlugInView.nib */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; path = PlugInView.nib; sourceTree = ""; }; - BD9DF0AE0DB41E780025C97C /* PlugInGUI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlugInGUI.h; sourceTree = ""; }; - BD9DF0AF0DB41E780025C97C /* PlugInGUI.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PlugInGUI.m; sourceTree = ""; }; - BD9DF0F90DB48C860025C97C /* CTGradient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CTGradient.h; sourceTree = ""; }; - BD9DF0FA0DB48C860025C97C /* CTGradient.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CTGradient.m; sourceTree = ""; }; - BDA8B1100D9F8A8500B3511A /* MMPlugInManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MMPlugInManager.h; sourceTree = ""; }; - BDA8B1110D9F8A8500B3511A /* MMPlugInManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MMPlugInManager.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -275,13 +253,6 @@ 1D145C7E0E5227CE00691AA0 /* MMTextViewHelper.m */, 1D8059220E118663001699D1 /* Miscellaneous.h */, 1D80591D0E1185EA001699D1 /* Miscellaneous.m */, - BD9DF0F90DB48C860025C97C /* CTGradient.h */, - BD9DF0FA0DB48C860025C97C /* CTGradient.m */, - BD476E2B0DAAD74400F08A5C /* RBSplitSubview.h */, - BD476E2C0DAAD74400F08A5C /* RBSplitSubview.m */, - BD476E2D0DAAD74400F08A5C /* RBSplitView.h */, - BD476E2E0DAAD74400F08A5C /* RBSplitView.m */, - BD476E2F0DAAD74400F08A5C /* RBSplitViewPrivateDefines.h */, 0395A8310D71ED7800881434 /* DBPrefsWindowController.h */, 0395A8320D71ED7800881434 /* DBPrefsWindowController.m */, 1DE3F8E80D50F84600052B9E /* MMPreferenceController.h */, @@ -312,13 +283,6 @@ 1D1474960C56703C0038FA2B /* MacVim.m */, 32CA4F630368D1EE00C91783 /* MacVim_Prefix.pch */, 29B97316FDCFA39411CA2CEA /* main.m */, - BDA8B1100D9F8A8500B3511A /* MMPlugInManager.h */, - BDA8B1110D9F8A8500B3511A /* MMPlugInManager.m */, - BD943D310DA2EA2500A02D9B /* PlugInInterface.h */, - BD943D510DA3050B00A02D9B /* PlugInImpl.h */, - BD943D520DA3050B00A02D9B /* PlugInImpl.m */, - BD9DF0AE0DB41E780025C97C /* PlugInGUI.h */, - BD9DF0AF0DB41E780025C97C /* PlugInGUI.m */, ); name = "MacVim Source"; sourceTree = ""; @@ -435,7 +399,6 @@ 1D8BEA73104992290069B072 /* FindAndReplace.nib */, 0395A8A90D72D88B00881434 /* General.png */, 1D22374A0E45DF4800E6FFFF /* Advanced.png */, - BD9DF09F0DB2BA020025C97C /* PlugInView.nib */, 1DD3D51D0D82D4C9006E4320 /* ibeam.png */, 1D0F11480D58C77800D5DA09 /* Font */, 1DE9726C0C48050600F96A9F /* Toolbar */, @@ -547,7 +510,6 @@ 1DE3F8E70D50F80500052B9E /* Preferences.nib in Resources */, 0395A8AA0D72D88B00881434 /* General.png in Resources */, 1DD3D51E0D82D4C9006E4320 /* ibeam.png in Resources */, - BD9DF0A00DB2BA020025C97C /* PlugInView.nib in Resources */, 1D22374B0E45DF4800E6FFFF /* Advanced.png in Resources */, 1DCD00BF0E50B2B700460166 /* Attention.png in Resources */, 1DCD00C00E50B2B700460166 /* Copy.png in Resources */, @@ -618,12 +580,6 @@ 1DE3F8EB0D50F84600052B9E /* MMPreferenceController.m in Sources */, 0395A8330D71ED7800881434 /* DBPrefsWindowController.m in Sources */, 1D80591F0E1185EA001699D1 /* Miscellaneous.m in Sources */, - BDA8B1120D9F8A8500B3511A /* MMPlugInManager.m in Sources */, - BD943D530DA3050B00A02D9B /* PlugInImpl.m in Sources */, - BD476E300DAAD74400F08A5C /* RBSplitSubview.m in Sources */, - BD476E310DAAD74400F08A5C /* RBSplitView.m in Sources */, - BD9DF0B00DB41E780025C97C /* PlugInGUI.m in Sources */, - BD9DF0FB0DB48C860025C97C /* CTGradient.m in Sources */, 1D145C7F0E5227CE00691AA0 /* MMTextViewHelper.m in Sources */, 1D60088B0E96A0B2003763F0 /* MMFindReplaceController.m in Sources */, 1DE63FFB0E71820F00959BDB /* MMCoreTextView.m in Sources */, diff --git a/src/MacVim/Miscellaneous.h b/src/MacVim/Miscellaneous.h index 6f0aee5f00..dfe9afb127 100644 --- a/src/MacVim/Miscellaneous.h +++ b/src/MacVim/Miscellaneous.h @@ -45,9 +45,6 @@ extern NSString *MMCurrentPreferencePaneKey; extern NSString *MMLoginShellCommandKey; extern NSString *MMLoginShellArgumentKey; extern NSString *MMDialogsTrackPwdKey; -#ifdef MM_ENABLE_PLUGINS -extern NSString *MMShowLeftPlugInContainerKey; -#endif extern NSString *MMOpenLayoutKey; extern NSString *MMVerticalSplitKey; extern NSString *MMPreloadCacheSizeKey; diff --git a/src/MacVim/Miscellaneous.m b/src/MacVim/Miscellaneous.m index 36d5e8b8d0..7d6e6d1419 100644 --- a/src/MacVim/Miscellaneous.m +++ b/src/MacVim/Miscellaneous.m @@ -37,9 +37,6 @@ NSString *MMCurrentPreferencePaneKey = @"MMCurrentPreferencePane"; NSString *MMLoginShellCommandKey = @"MMLoginShellCommand"; NSString *MMLoginShellArgumentKey = @"MMLoginShellArgument"; NSString *MMDialogsTrackPwdKey = @"MMDialogsTrackPwd"; -#ifdef MM_ENABLE_PLUGINS -NSString *MMShowLeftPlugInContainerKey = @"MMShowLeftPlugInContainer"; -#endif NSString *MMOpenLayoutKey = @"MMOpenLayout"; NSString *MMVerticalSplitKey = @"MMVerticalSplit"; NSString *MMPreloadCacheSizeKey = @"MMPreloadCacheSize"; diff --git a/src/MacVim/PlugInGUI.h b/src/MacVim/PlugInGUI.h deleted file mode 100644 index 445f8142e2..0000000000 --- a/src/MacVim/PlugInGUI.h +++ /dev/null @@ -1,57 +0,0 @@ -/* vi:set ts=8 sts=4 sw=4 ft=objc: - * - * VIM - Vi IMproved by Bram Moolenaar - * MacVim GUI port by Bjorn Winckler - * - * Do ":help uganda" in Vim to read copying and usage conditions. - * Do ":help credits" in Vim to see a list of people who contributed. - * See README.txt for an overview of the Vim source code. - */ - -#import -#import "RBSplitView.h" - - -@class MMPlugInView; -@class MMPlugInViewContainer; -@class MMPlugInViewController; - -@interface MMPlugInViewHeader : NSView { - IBOutlet MMPlugInViewController *controller; -} -@end - -@interface MMPlugInView : RBSplitSubview { - IBOutlet MMPlugInViewController *controller; -} - -- (MMPlugInViewController *)controller; - -@end - -@interface MMPlugInViewController : NSObject { - IBOutlet RBSplitSubview *plugInSubview; - IBOutlet MMPlugInViewHeader *headerView; - IBOutlet NSView *contentView; - IBOutlet NSTextField *titleField; -} - -- (id)initWithView:(NSView *)view title:(NSString *)title; -- (void)moveToContainer:(MMPlugInViewContainer *)container; -- (RBSplitSubview *)plugInSubview; -- (MMPlugInViewContainer *)container; - -// called when the dropView on the container holding this plugin view was -// changed, and this was the current dropView or it is the new dropView -- (void)dropViewChanged; -@end - -@interface MMPlugInViewContainer : RBSplitView { - RBSplitSubview *fillerView; - - // only used during drag and drop - MMPlugInView *dropView; -} - -- (MMPlugInView *)dropView; -@end diff --git a/src/MacVim/PlugInGUI.m b/src/MacVim/PlugInGUI.m deleted file mode 100644 index b1e272002d..0000000000 --- a/src/MacVim/PlugInGUI.m +++ /dev/null @@ -1,334 +0,0 @@ -/* vi:set ts=8 sts=4 sw=4 ft=objc: - * - * VIM - Vi IMproved by Bram Moolenaar - * MacVim GUI port by Bjorn Winckler - * - * Do ":help uganda" in Vim to read copying and usage conditions. - * Do ":help credits" in Vim to see a list of people who contributed. - * See README.txt for an overview of the Vim source code. - */ - -/* - * MMPlugInViewHeader - * - * Essentially just a title bar for a plugin view. Handles drawing the - * drag-and-drop line where a new plugin view will be inserted. - * - * MMPlugInView - * - * This contains a single view added by a plugin. - * - * MMPlugInViewContainer - * - * This contains multiple MMPlugInViews. It handles the drag and drop aspects - * of the views, as well. - * - * Author: Matt Tolton - */ -#import "MacVim.h" - -#ifdef MM_ENABLE_PLUGINS - -#import "PlugInGUI.h" -#import "CTGradient.h" - -NSString *MMPlugInViewPboardType = @"MMPlugInViewPboardType"; - -@implementation MMPlugInViewHeader - -- (void)mouseDown:(NSEvent *)theEvent -{ - // Make image from view - NSView *view = self; - [view lockFocus]; - NSBitmapImageRep *bitmap = [[[NSBitmapImageRep alloc] - initWithFocusedViewRect: [view bounds]] autorelease]; - [view unlockFocus]; - - NSImage *image = [[[NSImage alloc] initWithSize: [view bounds].size] - autorelease]; - [image addRepresentation:bitmap]; - - NSPasteboard *pboard = [NSPasteboard pasteboardWithName:NSDragPboard]; - - [pboard declareTypes:[NSArray arrayWithObject:MMPlugInViewPboardType] - owner:self]; - - NSPoint pt = [view convertPoint:[view bounds].origin - toView:[controller plugInSubview]]; - [[controller plugInSubview] dragImage:image - at:pt - offset:NSMakeSize(0, 0) - event:theEvent - pasteboard:pboard - source:controller - slideBack:YES]; -} - -- (void)drawRect:(NSRect)rect -{ - NSColor *startColor; - startColor = [NSColor colorWithCalibratedRed:.600 - green:.600 - blue:.600 - alpha:1.0]; - - NSColor *endColor = [NSColor colorWithCalibratedRed:.800 - green:.800 - blue:.800 - alpha:1.0]; - - CTGradient *grad = [CTGradient gradientWithBeginningColor:startColor - endingColor:endColor]; - [grad fillRect:[self bounds] angle:90]; - - MMPlugInView *dropView = [[controller container] dropView]; - - if (dropView == [controller plugInSubview]) { - NSRect insertionRect = NSMakeRect(0,[self bounds].size.height - 2, - [self bounds].size.width, 2); - [[NSColor redColor] set]; - NSRectFill(insertionRect); - } -} - -- (BOOL)isOpaque -{ - return YES; -} - -- (NSRect)dragRect -{ - return NSMakeRect(0, [self bounds].size.height - 6, [self bounds].size.width, 6); -} - -@end - -@implementation MMPlugInView - -- (MMPlugInViewController *)controller -{ - return controller; -} - -@end - -@implementation MMPlugInViewController - -- (id)initWithView:(NSView *)view title:(NSString *)title -{ - if ((self = [super init]) == nil) return nil; - - if (![NSBundle loadNibNamed:@"PlugInView" owner:self]) - ASLogErr(@"Error loading PlugIn nib"); - - [titleField setStringValue:title]; - - [plugInSubview setMinDimension:50 - andMaxDimension:0.0]; - - [view setFrame:[contentView bounds]]; - [contentView addSubview:view]; - - return self; -} - -- (RBSplitSubview *)plugInSubview -{ - return plugInSubview; -} - -- (void)moveToContainer:(MMPlugInViewContainer *)container -{ - if ([plugInSubview splitView]) { - [plugInSubview removeFromSuperview]; - } - [container addSubview:plugInSubview]; -} - -- (void)moveToContainer:(MMPlugInViewContainer *)container before:(MMPlugInView *)lowerView -{ - if ([plugInSubview splitView]) { - [plugInSubview removeFromSuperview]; - } - [container addSubview:plugInSubview positioned:NSWindowBelow relativeTo:lowerView]; -} - -- (MMPlugInViewHeader *)headerView -{ - return headerView; -} - -- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal -{ - if (isLocal) - return NSDragOperationPrivate; - else - return NSDragOperationNone; -} - -- (void)dropViewChanged { - [headerView setNeedsDisplay:YES]; -} - -- (MMPlugInViewContainer *)container { - return (MMPlugInViewContainer *)[plugInSubview splitView]; -} -@end - -@implementation MMPlugInViewContainer - -- (id)initWithFrame:(NSRect)frame -{ - if ((self = [super initWithFrame:frame]) == nil) return nil; - - [self registerForDraggedTypes: - [NSArray arrayWithObjects:MMPlugInViewPboardType, nil]]; - - [self setVertical:NO]; - [self setDelegate:self]; - - fillerView = [[RBSplitSubview alloc] initWithFrame:NSMakeRect(0,0,0,0)]; - [fillerView setHidden:YES]; - - return self; -} - -- (void)dealloc -{ - ASLogDebug(@""); - - [fillerView release]; fillerView = nil; - [super dealloc]; -} - -- (unsigned int)splitView:(RBSplitView*)sender dividerForPoint:(NSPoint)point - inSubview:(RBSplitSubview*)subview -{ - MMPlugInViewController *controller = [(MMPlugInView *)subview controller]; - MMPlugInViewHeader *header = [controller headerView]; - - if ([header mouse:[header convertPoint:point fromView:sender] - inRect:[header dragRect]]) - return [subview position] - 1; - - return NSNotFound; -} - -- (NSRect)splitView:(RBSplitView*)sender cursorRect:(NSRect)rect - forDivider:(unsigned int)theDivider -{ - - if (theDivider != 0) return NSZeroRect; - - int i; - for (i = 1;; i++) { - MMPlugInView *view = (MMPlugInView *)[sender subviewAtPosition:i]; - if (!view) break; - - MMPlugInViewHeader *header = [[view controller] headerView]; - NSRect rect = [header dragRect]; - rect = [sender convertRect:rect fromView:header]; - [sender addCursorRect:rect - cursor:[RBSplitView cursor:RBSVHorizontalCursor]]; - - } - - return NSZeroRect; -} - -- (void)clearDragInfo -{ - if (dropView) { - MMPlugInView *save = dropView; - dropView = nil; - [[save controller] dropViewChanged]; - } -} - -// point should be in the window's coordinate system -- (void)updateDragInfo:(id)info -{ - - [self clearDragInfo]; - - if (!([info draggingSourceOperationMask] & NSDragOperationPrivate)) return; - - if (![[info draggingSource] isKindOfClass:[MMPlugInViewController class]]) return; - - // for now has to be THIS container. in the future, it will be ok for any - // container associated with the same vim instance - if ([[info draggingSource] container] != self) return; - - // XXX for now we just use the view that the mouse is currently over, and - // always insert "above" that view. In the future, we might want to try to - // find the divider that the mouse is closest to and have the dropView be - // the view below that divider. - - NSPoint point = [info draggingLocation]; - - int i; - for (i = 0;; i++) { - MMPlugInView *subview = (MMPlugInView *)[self subviewAtPosition:i]; - if (!subview) break; - - if ([subview mouse:[subview convertPoint:point fromView:nil] - inRect:[subview bounds]]) { - dropView = subview; - break; - } - } - - if ([[info draggingSource] plugInSubview] == dropView) - dropView = nil; - - if (dropView) [[dropView controller] dropViewChanged]; -} - -- (NSDragOperation)draggingEntered:(id)sender -{ - [self updateDragInfo:sender]; - - if (dropView != nil) - return NSDragOperationPrivate; - else - return NSDragOperationNone; -} - -- (NSDragOperation)draggingUpdated:(id)sender -{ - [self updateDragInfo:sender]; - - if (dropView != nil) - return NSDragOperationPrivate; - - return NSDragOperationNone; -} - -- (BOOL)prepareForDragOperation:(id)sender -{ - [self updateDragInfo:sender]; - return dropView != nil; -} - -- (BOOL)performDragOperation:(id)sender -{ - MMPlugInViewController *source = [sender draggingSource]; - [source moveToContainer:self before:dropView]; - [self clearDragInfo]; - return YES; -} - -- (void)draggingExited:(id)sender -{ - [self clearDragInfo]; -} - - -- (MMPlugInView *)dropView { - return dropView; -} - -@end - -#endif diff --git a/src/MacVim/PlugInImpl.h b/src/MacVim/PlugInImpl.h deleted file mode 100644 index 6ab4daee66..0000000000 --- a/src/MacVim/PlugInImpl.h +++ /dev/null @@ -1,37 +0,0 @@ -/* vi:set ts=8 sts=4 sw=4 ft=objc: - * - * VIM - Vi IMproved by Bram Moolenaar - * MacVim GUI port by Bjorn Winckler - * - * Do ":help uganda" in Vim to read copying and usage conditions. - * Do ":help credits" in Vim to see a list of people who contributed. - * See README.txt for an overview of the Vim source code. - */ - -#import -#import "PlugInInterface.h" - -@interface MMPlugInAppMediator : NSObject { - NSMenu *plugInMenu; -} - -+ (MMPlugInAppMediator *)sharedAppMediator; - -@end - - -@class MMVimController; - -// One of these per vim controller object. It manages all of the plugin -// instances for a given controller. -@interface MMPlugInInstanceMediator : NSObject { - // NB: this is a weak reference to the vim controller - MMVimController *vimController; - NSMutableArray *instances; - NSDrawer *drawer; - NSMutableArray *plugInViews ; -} - -- (id)initWithVimController:(MMVimController *)controller; - -@end diff --git a/src/MacVim/PlugInImpl.m b/src/MacVim/PlugInImpl.m deleted file mode 100644 index 8f272b78d6..0000000000 --- a/src/MacVim/PlugInImpl.m +++ /dev/null @@ -1,237 +0,0 @@ -/* vi:set ts=8 sts=4 sw=4 ft=objc: - * - * VIM - Vi IMproved by Bram Moolenaar - * MacVim GUI port by Bjorn Winckler - * - * Do ":help uganda" in Vim to read copying and usage conditions. - * Do ":help credits" in Vim to see a list of people who contributed. - * See README.txt for an overview of the Vim source code. - */ - -/* - * MMPlugInInstanceMediator - * - * Implementation of the PlugInInstanceMediator protocol. One of these is - * created per vim instance. It manages all of the plugin instances for that - * vim instance. - * - * MMPlugInAppMediator - * - * Implementation of the PlugInAppMediator protocol. Singleton class. - * - * Author: Matt Tolton - */ - -#import "Miscellaneous.h" - -#ifdef MM_ENABLE_PLUGINS - -static int MMPlugInArchMajorVersion = 1; -static int MMPlugInArchMinorVersion = 0; - -#import "PlugInImpl.h" -#import "PlugInGUI.h" -#import "MMPlugInManager.h" -#import "RBSplitView.h" -#import "MMAppController.h" -#import "MMVimController.h" - - -@implementation MMPlugInInstanceMediator - -- (void)setupDrawer -{ - // XXX The drawer does not work in full screen mode. Eventually, the - // drawer will go away so I'm ignoring this issue for now. - drawer = [[NSDrawer alloc] initWithContentSize:NSMakeSize(200,100) - preferredEdge:NSMinXEdge]; - - - NSSize contentSize = [drawer contentSize]; - - // XXX memory management for this - MMPlugInViewContainer *containerView = [[MMPlugInViewContainer alloc] - initWithFrame:NSMakeRect(0, 0, contentSize.width, contentSize.height)]; - - [drawer setContentView:containerView]; - - [containerView release]; - - [drawer setParentWindow:[[vimController windowController] window]]; -} - -- (void)toggleDrawer -{ - [drawer toggle:nil]; - [[NSUserDefaults standardUserDefaults] - setBool:[drawer state] == NSDrawerOpenState - || [drawer state] == NSDrawerOpeningState - forKey:MMShowLeftPlugInContainerKey]; -} - -- (void)initializeInstances -{ - NSArray *plugInClasses = [[MMPlugInManager sharedManager] plugInClasses]; - int i, count = [plugInClasses count]; - for (i = 0; i < count; i++) { - Class plugInClass = [plugInClasses objectAtIndex:i]; - if ([plugInClass instancesRespondToSelector: - @selector(initWithMediator:)]) { - id instance = [[[plugInClass alloc] initWithMediator:self] autorelease]; - [instances addObject:instance]; - } - } -} - -- (id)initWithVimController:(MMVimController *)controller -{ - if ((self = [super init]) == nil) return nil; - vimController = controller; - instances = [[NSMutableArray alloc] init]; - plugInViews = [[NSMutableArray alloc] init]; - - [self setupDrawer]; - [self initializeInstances]; - - return self; -} - -- (void)dealloc -{ - ASLogDebug(@""); - - [plugInViews release]; plugInViews = nil; - [instances release]; instances = nil; - [drawer release]; drawer = nil; - vimController = nil; - - [super dealloc]; -} - -- (id)evaluateVimExpression:(NSString *)vimExpression -{ - NSString *errstr = nil; - id res = [vimController evaluateVimExpressionCocoa:vimExpression - errorString:&errstr]; - if (!res) { - // Setting format to %@ instead of just passing errstr avoids warning. - [NSException raise:@"VimEvaluationException" format:@"%@", errstr]; - } - - return res; -} - -- (void)addVimInput:(NSString *)input -{ - [vimController addVimInput:input]; -} - -- (void)addPlugInView:(NSView *)view withTitle:(NSString *)title -{ - // Do this here so that the drawer is never opened automatically when there - // are no plugin views. - if ([[NSUserDefaults standardUserDefaults] - boolForKey:MMShowLeftPlugInContainerKey] && [plugInViews count] == 0) - [drawer open]; - - MMPlugInViewController *newView = - [[MMPlugInViewController alloc] initWithView:view title:title]; - - [plugInViews addObject:newView]; - - [newView moveToContainer:(MMPlugInViewContainer *)[drawer contentView]]; - - [newView release]; -} - -- (void)openFiles:(NSArray *)filenames -{ - [vimController dropFiles:filenames forceOpen:YES]; -} - -- (id)instanceWithClass:(Class)class -{ - int i, count = [instances count]; - for (i = 0; i < count; i++) { - id instance = [instances objectAtIndex:i]; - if ([instance isKindOfClass:class]) - return instance; - } - - return nil; -} - -@end - -@implementation MMPlugInAppMediator - -MMPlugInAppMediator *sharedAppMediator = nil; - -+ (MMPlugInAppMediator *)sharedAppMediator -{ - if (sharedAppMediator == nil) - sharedAppMediator = [[MMPlugInAppMediator alloc] init]; - - return sharedAppMediator; -} - -- (id)init -{ - if ((self = [super init]) == nil) return nil; - - NSString *title = NSLocalizedString(@"Toggle Left Drawer", - @"Toggle Left Drawer menu title"); - NSMenuItem *item = [[[NSMenuItem alloc] initWithTitle:title - action:@selector(toggleLeftDrawer:) - keyEquivalent:@""] autorelease]; - [item setTarget:self]; - [self addPlugInMenuItem:item]; - [self addPlugInMenuItem:[NSMenuItem separatorItem]]; - - return self; -} - -- (void)toggleLeftDrawer:(id)sender -{ - MMVimController *c = [[MMAppController sharedInstance] keyVimController]; - - [[c instanceMediator] toggleDrawer]; -} - -- (BOOL)validateMenuItem:(NSMenuItem *)item -{ - return [[MMAppController sharedInstance] keyVimController] != nil; -} - -- (void)addPlugInMenuItem:(NSMenuItem *)menuItem -{ - NSAssert(menuItem, @"menuItem cannot be nil"); - [[MMAppController sharedInstance] addItemToPlugInMenu:menuItem]; -} - -// It is a little bit ugly having to pass the class in here. An alternative -// would be to have a 1:1 relationship between app mediators and plugins, so -// that we'd know exactly which plugin class to look for. -- (id)keyPlugInInstanceWithClass:(Class)class -{ - MMVimController *keyVimController = [[NSApp delegate] keyVimController]; - - if (keyVimController) - return [[keyVimController instanceMediator] instanceWithClass:class]; - - return nil; -} - -- (int)majorVersion -{ - return MMPlugInArchMajorVersion; -} - -- (int)minorVersion -{ - return MMPlugInArchMinorVersion; -} - -@end - -#endif diff --git a/src/MacVim/PlugInInterface.h b/src/MacVim/PlugInInterface.h deleted file mode 100644 index dbbf4b64f8..0000000000 --- a/src/MacVim/PlugInInterface.h +++ /dev/null @@ -1,72 +0,0 @@ -/* vi:set ts=8 sts=4 sw=4 ft=objc: - * - * VIM - Vi IMproved by Bram Moolenaar - * MacVim GUI port by Bjorn Winckler - * - * Do ":help uganda" in Vim to read copying and usage conditions. - * Do ":help credits" in Vim to see a list of people who contributed. - * See README.txt for an overview of the Vim source code. - */ - -// This header file should include everything that a plug-in will need so that -// it is all we need to distribute for plug-in developers. - -/* - * PlugInAppMediator - * - * The interface that the plugin may use to interact with the MacVim - * application. - * - * PlugInInstanceMediator - * - * The interface that a plugin may use to interact with a specific vim instance - * within MacVim. - * - * PlugInProtocol - * - * The protocol which the principal class of the plugin must conform to. - * - * Author: Matt Tolton - * - */ - -@protocol PlugInAppMediator - -- (void)addPlugInMenuItem:(NSMenuItem *)menuItem; - -// Returns the plugin instance of the specified class associated with the key vim window. -// If a vim window is not the key window, returns nil. -// If there are no instances with the specified class, returns nil. -- (id)keyPlugInInstanceWithClass:(Class)class; - -// Plugin architecture version. Major versions indicate API incompatibilities. -// Minor versions may include additions, but nothing that should break current -// plugins. -- (int)majorVersion; -- (int)minorVersion; - -@end - -@protocol PlugInInstanceMediator - -// vim values are converted into NSNumber, NSString, NSArray, and NSDictionary -- (id)evaluateVimExpression:(NSString *)vimExpression; -- (void)addVimInput:(NSString *)input; -- (void)openFiles:(NSArray *)fileNames; -- (void)addPlugInView:(NSView *)view withTitle:(NSString *)title; - -@end - -@protocol PlugInProtocol -// The mediator should not be retained. It will exist until terminatePlugIn is -// called. -+ (BOOL)initializePlugIn:(id)mediator; -+ (void)terminatePlugIn; -@end - -@interface NSObject (PlugInProtocol) -// The mediator should not be retained. It will exist until it releases this -// plugin instance, and is not valid after that. -- (id)initWithMediator:(id)mediator; -@end - diff --git a/src/MacVim/PlugInView.nib/classes.nib b/src/MacVim/PlugInView.nib/classes.nib deleted file mode 100644 index ae787f49da..0000000000 --- a/src/MacVim/PlugInView.nib/classes.nib +++ /dev/null @@ -1,98 +0,0 @@ - - - - - IBClasses - - - CLASS - MMPlugInView - LANGUAGE - ObjC - OUTLETS - - controller - MMPlugInViewController - - SUPERCLASS - RBSplitSubview - - - CLASS - MMPlugInViewController - LANGUAGE - ObjC - OUTLETS - - contentView - NSView - headerView - MMPlugInViewHeader - plugInSubview - RBSplitSubview - titleField - NSTextField - - SUPERCLASS - NSObject - - - CLASS - RBSplitView - LANGUAGE - ObjC - OUTLETS - - delegate - id - - SUPERCLASS - RBSplitSubview - - - CLASS - RBSplitSubview - LANGUAGE - ObjC - SUPERCLASS - NSView - - - CLASS - FirstResponder - LANGUAGE - ObjC - SUPERCLASS - NSObject - - - ACTIONS - - didAdjustSubviews - RBSplitView - willAdjustSubviews - RBSplitView - - CLASS - NSObject - LANGUAGE - ObjC - - - CLASS - MMPlugInViewHeader - LANGUAGE - ObjC - OUTLETS - - controller - MMPlugInViewController - - SUPERCLASS - NSView - - - IBVersion - 1 - - diff --git a/src/MacVim/PlugInView.nib/info.nib b/src/MacVim/PlugInView.nib/info.nib deleted file mode 100644 index 668fd0b86d..0000000000 --- a/src/MacVim/PlugInView.nib/info.nib +++ /dev/null @@ -1,20 +0,0 @@ - - - - - IBFramework Version - 629 - IBLastKnownRelativeProjectPath - ../MacVim.xcodeproj - IBOldestOS - 5 - IBOpenObjects - - 6 - - IBSystem Version - 9D34 - targetFramework - IBCocoaFramework - - diff --git a/src/MacVim/PlugInView.nib/keyedobjects.nib b/src/MacVim/PlugInView.nib/keyedobjects.nib deleted file mode 100644 index 28b0310c15..0000000000 Binary files a/src/MacVim/PlugInView.nib/keyedobjects.nib and /dev/null differ diff --git a/src/MacVim/RBSplitSubview.h b/src/MacVim/RBSplitSubview.h deleted file mode 100644 index d058230526..0000000000 --- a/src/MacVim/RBSplitSubview.h +++ /dev/null @@ -1,146 +0,0 @@ -// -// RBSplitSubview.h version 1.1.4 -// RBSplitView -// -// Created by Rainer Brockerhoff on 19/11/2004. -// Copyright 2004-2006 Rainer Brockerhoff. -// Some Rights Reserved under the Creative Commons Attribution License, version 2.5, and/or the MIT License. -// - -#import - -@class RBSplitView; - -// These values are used to inquire about the status of a subview. -typedef enum { - RBSSubviewExpanding=-2, - RBSSubviewCollapsing=-1, - RBSSubviewNormal=0, - RBSSubviewCollapsed=1 -} RBSSubviewStatus; - -@interface RBSplitSubview : NSView { -// Subclasses normally should use setter methods instead of changing instance variables by assignment. -// Most getter methods simply return the corresponding instance variable, so with some care, subclasses -// could reference them directly. - NSString* identifier; // An identifier string for the subview, default is @"". - int tag; // A tag integer for the subview, default is 0. - float minDimension; // The minimum dimension. Must be 1.0 or any larger integer. - float maxDimension; // The maximum dimension. Must be at least equal to the minDimension. - // Set to a large number if there's no maximum. - double fraction; // A fractional part of the dimension, used for proportional resizing. - // Normally varies between -0.999... and 0.999... - // When collapsed, holds the proportion of the RBSplitView's dimension - // the view was occupying before collapsing. - NSRect previous; // Holds the frame rect for the last delegate notification. - NSSize savedSize; // This holds the size the subview had before it was resized beyond - // its minimum or maximum limits. Valid if notInLimits is YES. - unsigned int actDivider; // This is set temporarily while an alternate drag view is being dragged. - BOOL canDragWindow; // This is set temporarily during a mouseDown on a non-opaque subview. - BOOL canCollapse; // YES if the subview can be collapsed. - BOOL notInLimits; // YES if the subview's dimensions are outside the set limits. -} - -// This class method returns YES if some RBSplitSubview is being animated. -+ (BOOL)animating; - -// This is the designated initializer for creating extra subviews programmatically. -- (id)initWithFrame:(NSRect)frame; - -// Returns the immediately containing RBSplitView, or nil if there is none. -// couplingSplitView returns nil if we're a non-coupled RBSplitView. -// outermostSplitView returns the outermost RBSplitView. -- (RBSplitView*)splitView; -- (RBSplitView*)couplingSplitView; -- (RBSplitView*)outermostSplitView; - -// Returns self if we're a RBSplitView, nil otherwise. Convenient for testing or calling methods. -// coupledSplitView returns nil if we're a non-coupled RBSplitView. -- (RBSplitView*)asSplitView; -- (RBSplitView*)coupledSplitView; - -// Sets and gets the coupling between the view and its containing RBSplitView (if any). Coupled -// RBSplitViews take some parameters, such as divider images, from the containing view. The default -// for RBSplitView is YES. However, calling setCoupled: on a RBSplitSubview will have no effect, -// and isCoupled will always return false. -- (void)setCoupled:(BOOL)flag; -- (BOOL)isCoupled; - -// Returns YES if the containing RBSplitView is horizontal. -- (BOOL)splitViewIsHorizontal; - -// Returns the number of subviews. Just a convenience method. -- (unsigned)numberOfSubviews; - -// Sets and gets the tag. -- (void)setTag:(int)theTag; -- (int)tag; - -// Sets and gets the identifier string. Will never be nil. -- (void)setIdentifier:(NSString*)aString; -- (NSString*)identifier; - -// Position means the subview's position within the RBSplitView - counts from zero left to right -// or top to bottom. Setting it will move the subview to another position without changing its size, -// status or attributes. Set position to 0 to move it to the start, or to some large number to move it -// to the end of the RBSplitView. -- (unsigned)position; -- (void)setPosition:(unsigned)newPosition; - -// Returns YES if the subview is collapsed. Collapsed subviews are squashed down to zero but never -// made smaller than the minimum dimension as far as their own subviews are concerned. If the -// subview is being animated this will return NO. -- (BOOL)isCollapsed; - -// This will return the current status of the subview. Negative values mean the subview is -// being animated. -- (RBSSubviewStatus)status; - -// Sets and gets the ability to collapse the subview. However, this can be overridden by the delegate. -- (BOOL)canCollapse; -- (void)setCanCollapse:(BOOL)flag; - -// Tests whether the subview can shrink or expand further. -- (BOOL)canShrink; -- (BOOL)canExpand; - -// Sets and gets the minimum and maximum dimensions. They're set at the same time to make sure values -// are consistent. Despite being floats, they'll always have integer values. The minimum value for the -// minimum is 1.0. Pass 0.0 for the maximum to set it to some huge number. -- (float)minDimension; -- (float)maxDimension; -- (void)setMinDimension:(float)newMinDimension andMaxDimension:(float)newMaxDimension; - -// Call this to expand a subview programmatically. It will return the subview's dimension after -// expansion. -- (float)expand; - -// Call this to collapse a subview programmatically. It will return the negative -// of the subview's dimension _before_ collapsing, or 0.0 if the subview can't be collapsed. -- (float)collapse; - -// These calls collapse and expand subviews with animation. They return YES if animation -// startup was successful. -- (BOOL)collapseWithAnimation; -- (BOOL)expandWithAnimation; - -// These methods collapse and expand subviews with animation, depending on the parameters. -// They return YES if animation startup was successful. If resize is NO, the subview is -// collapsed/expanded without resizing it during animation. -- (BOOL)collapseWithAnimation:(BOOL)animate withResize:(BOOL)resize; -- (BOOL)expandWithAnimation:(BOOL)animate withResize:(BOOL)resize; - -// Returns the current dimension of the subview. -- (float)dimension; - -// Sets the current dimension of the subview, subject to the current maximum and minimum. -// If the subview is collapsed, this has no immediate effect. -- (void)setDimension:(float)value; - -// This method is used internally when a divider is dragged. It tries to change the subview's dimension -// and returns the actual change, collapsing or expanding whenever possible. You usually won't need -// to call this directly. -- (float)changeDimensionBy:(float)increment mayCollapse:(BOOL)mayCollapse move:(BOOL)move; - -@end - diff --git a/src/MacVim/RBSplitSubview.m b/src/MacVim/RBSplitSubview.m deleted file mode 100644 index 60a01ded57..0000000000 --- a/src/MacVim/RBSplitSubview.m +++ /dev/null @@ -1,929 +0,0 @@ -// -// RBSplitSubview.m version 1.1.4 -// RBSplitView -// -// Created by Rainer Brockerhoff on 19/11/2004. -// Copyright 2004-2006 Rainer Brockerhoff. -// Some Rights Reserved under the Creative Commons Attribution License, version 2.5, and/or the MIT License. -// -#ifdef MM_ENABLE_PLUGINS - -#import "RBSplitView.h" -#import "RBSplitViewPrivateDefines.h" - -// This variable points to the animation data structure while an animation is in -// progress; if there's none, it will be NULL. Animating may be very CPU-intensive so -// we allow only one animation to take place at a time. -static animationData* currentAnimation = NULL; - -@implementation RBSplitSubview - -// This class method returns YES if an animation is in progress. -+ (BOOL)animating { - return currentAnimation!=NULL; -} - -// This is the designated initializer for RBSplitSubview. It sets some reasonable defaults. However, you -// can't rely on anything working until you insert it into a RBSplitView. -- (id)initWithFrame:(NSRect)frame { - self = [super initWithFrame:frame]; - if (self) { - fraction = 0.0; - canCollapse = NO; - notInLimits = NO; - minDimension = 1.0; - maxDimension = WAYOUT; - identifier = @""; - previous = NSZeroRect; - savedSize = frame.size; - actDivider = NSNotFound; - canDragWindow = NO; - } - return self; -} - -// Just releases our stuff when going away. -- (void)dealloc { - [identifier release]; - [super dealloc]; -} - -// These return nil since we're not a RBSplitView (they're overridden there). -- (RBSplitView*)asSplitView { - return nil; -} - -- (RBSplitView*)coupledSplitView { - return nil; -} - -// Sets and gets the coupling between a RBSplitView and its containing RBSplitView (if any). -// For convenience, these methods are also implemented here. -- (void)setCoupled:(BOOL)flag { -} - -- (BOOL)isCoupled { - return NO; -} - -// RBSplitSubviews are never flipped, unless they're RBSplitViews. -- (BOOL)isFlipped { - return NO; -} - -// We copy the opacity of the owning split view. -- (BOOL)isOpaque { - return [[self couplingSplitView] isOpaque]; -} - -// A hidden RBSplitSubview is not redrawn and is not considered for drawing dividers. -// This won't work before 10.3, though. -- (void)setHidden:(BOOL)flag { - if ([self isHidden]!=flag) { - RBSplitView* sv = [self splitView]; - [self RB___setHidden:flag]; - if (flag) { - [sv adjustSubviews]; - } else { - [sv adjustSubviewsExcepting:self]; - } - } -} - -// RBSplitSubviews can't be in the responder chain. -- (BOOL)acceptsFirstResponder { - return NO; -} - -// Mousing down should move the window only for a completely transparent background. This might have -// unintended side effects in metal windows, so for those you might want to use a background color -// with a very low alpha (0.01 for instance). -// This is commented out as I'm still experimenting with it. -/*- (BOOL)mouseDownCanMoveWindow { - RBSplitView* sv = [self asSplitView]; - if (!sv) { - sv = [self couplingSplitView]; - } - return [sv background]==nil; - return YES; -}*/ - -// This returns the owning splitview. It's guaranteed to return a RBSplitView or nil. -// You should avoid having "orphan" RBSplitSubviews, or at least manipulating -// them while they're not inserted in a RBSplitView. -- (RBSplitView*)splitView { - id result = [self superview]; - if ([result isKindOfClass:[RBSplitView class]]) { - return (RBSplitView*)result; - } - return nil; -} - -// This also returns the owning splitview. It's overridden for nested RBSplitViews. -- (RBSplitView*)couplingSplitView { - id result = [self superview]; - if ([result isKindOfClass:[RBSplitView class]]) { - return (RBSplitView*)result; - } - return nil; -} - -// This returns the outermost directly containing RBSplitView, or nil. -- (RBSplitView*)outermostSplitView { - id result = nil; - id sv = self; - while ((sv = [sv superview])&&[sv isKindOfClass:[RBSplitView class]]) { - result = sv; - } - return result; -} - -// This convenience method returns YES if the containing RBSplitView is horizontal. -- (BOOL)splitViewIsHorizontal { - return [[self splitView] isHorizontal]; -} - -// You can use either tags (ints) or identifiers (NSStrings) to identify individual subviews. -// We take care not to have nil identifiers. -- (void)setTag:(int)theTag { - tag = theTag; -} - -- (int)tag { - return tag; -} - -- (void)setIdentifier:(NSString*)aString { - [identifier autorelease]; - identifier = aString?[aString retain]:@""; -} - -- (NSString*)identifier { - return identifier; -} - -// If we have an identifier, this will make debugging a little easier by appending it to the -// default description. -- (NSString*)description { - return [identifier length]>0?[NSString stringWithFormat:@"%@(%@)",[super description],identifier]:[super description]; -} - -// This pair of methods allows you to get and change the position of a subview (within the split view); -// this counts from zero from the left or top of the split view. -- (unsigned)position { - RBSplitView* sv = [self splitView]; - return sv?[[sv subviews] indexOfObjectIdenticalTo:self]:0; -} - -- (void)setPosition:(unsigned)newPosition { - RBSplitView* sv = [self splitView]; - if (sv) { - [self retain]; - [self removeFromSuperviewWithoutNeedingDisplay]; - NSArray* subviews = [sv subviews]; - if (newPosition>=[subviews count]) { - [sv addSubview:self positioned:NSWindowAbove relativeTo:nil]; - } else { - [sv addSubview:self positioned:NSWindowBelow relativeTo:[subviews objectAtIndex:newPosition]]; - } - [self release]; - } -} - -// Tests whether the subview is collapsed. -- (BOOL)isCollapsed { - return [self RB___visibleDimension]<=0.0; -} - -// Tests whether the subview can shrink further. -- (BOOL)canShrink { - return [self RB___visibleDimension]>([self canCollapse]?0.0:minDimension); -} - -// Tests whether the subview can expand further. -- (BOOL)canExpand { - return [self RB___visibleDimension]collapsing?RBSSubviewCollapsing:RBSSubviewExpanding; - } - return [self RB___visibleDimension]<=0.0?RBSSubviewCollapsed:RBSSubviewNormal; -} - -// Tests whether the subview can be collapsed. The local instance variable will be overridden by the -// delegate method if it's implemented. -- (BOOL)canCollapse { - BOOL result = canCollapse; - RBSplitView* sv = [self splitView]; - if ([sv RB___numberOfSubviews]<2) { - return NO; - } - id delegate = [sv delegate]; - if ([delegate respondsToSelector:@selector(splitView:canCollapse:)]) { - result = [delegate splitView:sv canCollapse:self]; - } - return result; -} - -// This sets the subview's "canCollapse" flag. Ignored if the delegate's splitView:canCollapse: -// method is implemented. -- (void)setCanCollapse:(BOOL)flag { - canCollapse = flag; -} - -// This expands a collapsed subview and calls the delegate's splitView:didExpand: method, if it exists. -// This is not called internally by other methods; call this to expand a subview programmatically. -// As a convenience to other methods, it returns the subview's dimension after expanding (this may be -// off by 1 pixel due to rounding) or 0.0 if it couldn't be expanded. -// The delegate should not change the subview's frame. -- (float)expand { - return [self RB___expandAndSetToMinimum:NO]; -} - -// This collapses an expanded subview and calls the delegate's splitView:didCollapse: method, if it exists. -// This is not called internally by other methods; call this to expand a subview programmatically. -// As a convenience to other methods, it returns the negative of the subview's dimension before -// collapsing (or 0.0 if it couldn't be collapsed). -// The delegate should not change the subview's frame. -- (float)collapse { - return [self RB___collapse]; -} - -// This tries to collapse the subview with animation, and collapses it instantly if some other -// subview is animating. Returns YES if animation was started successfully. -- (BOOL)collapseWithAnimation { - return [self collapseWithAnimation:YES withResize:YES]; -} - -// This tries to expand the subview with animation, and expands it instantly if some other -// subview is animating. Returns YES if animation was started successfully. -- (BOOL)expandWithAnimation { - return [self expandWithAnimation:YES withResize:YES]; -} - -// These methods collapse and expand subviews with animation, depending on the parameters. -// They return YES if animation startup was successful. If resize is NO, the subview is -// collapsed/expanded without resizing it during animation. -- (BOOL)collapseWithAnimation:(BOOL)animate withResize:(BOOL)resize { - if ([self status]==RBSSubviewNormal) { - if ([self canCollapse]) { - if (animate&&[self RB___animationData:YES resize:resize]) { - [self RB___clearResponder]; - [self RB___stepAnimation]; - return YES; - } else { - [self RB___collapse]; - } - } - } - return NO; -} - -- (BOOL)expandWithAnimation:(BOOL)animate withResize:(BOOL)resize { - if ([self status]==RBSSubviewCollapsed) { - if (animate&&[self RB___animationData:YES resize:resize]) { - [self RB___stepAnimation]; - return YES; - } else { - [self RB___expandAndSetToMinimum:NO]; - } - } - return NO; -} - - -// These 3 methods get and set the view's minimum and maximum dimensions. -// The minimum dimension ought to be an integer at least equal to 1.0 but we make sure. -// The maximum dimension ought to be an integer at least equal to the minimum. As a convenience, -// pass in zero to set it to some huge number. -- (float)minDimension { - return minDimension; -} - -- (float)maxDimension { - return maxDimension; -} - -- (void)setMinDimension:(float)newMinDimension andMaxDimension:(float)newMaxDimension { - minDimension = MAX(1.0,floorf(newMinDimension)); - if (newMaxDimension<1.0) { - newMaxDimension = WAYOUT; - } - maxDimension = MAX(minDimension,floorf(newMaxDimension)); - float dim = [self dimension]; - if ((dimmaxDimension)) { - [[self splitView] setMustAdjust]; - } -} - -// This returns the subview's dimension. If it's collapsed, it returns the dimension it would have -// after expanding. -- (float)dimension { - float dim = [self RB___visibleDimension]; - if (dim<=0.0) { - dim = [[self splitView] RB___dimensionWithoutDividers]*fraction; - if (dimmaxDimension) { - dim = maxDimension; - } - } - return dim; -} - -// Sets the current dimension of the subview, subject to the current maximum and minimum. -// If the subview is collapsed, this will have an effect only after reexpanding. -- (void)setDimension:(float)value { - RBSplitView* sv = [self splitView]; - NSSize size = [self frame].size; - BOOL ishor = [sv isHorizontal]; - if (DIM(size)>0.0) { -// We're not collapsed, set the size and adjust other subviews. - DIM(size) = value; - [self setFrameSize:size]; - [sv adjustSubviewsExcepting:self]; - } else { -// We're collapsed, adjust the fraction so that we'll have the (approximately) correct -// dimension after expanding. - fraction = value/[sv RB___dimensionWithoutDividers]; - } -} - -// This just draws the background of a subview, then tells the delegate, if any. -// The delegate would usually draw a frame inside the subview. -- (void)drawRect:(NSRect)rect { - RBSplitView* sv = [self splitView]; - NSColor* bg = [sv background]; - if (bg) { - [bg set]; - NSRectFillUsingOperation(rect,NSCompositeSourceOver); - } - id del = [sv delegate]; - if ([del respondsToSelector:@selector(splitView:willDrawSubview:inRect:)]) { - [del splitView:sv willDrawSubview:self inRect:rect]; - } -} - -// We check if the RBSplitView must be adjusted before redisplaying programmatically. -// if so, we adjust and display the whole RBSplitView. -- (void)display { - RBSplitView* sv = [self splitView]; - if (sv) { - if ([sv mustAdjust]) { - [sv display]; - } else { - [super display]; - } - } -} - -// RBSplitSubviews will always resize their own subviews. -- (BOOL)autoresizesSubviews { - return YES; -} - -// This is method is called automatically when the subview is resized; don't call it yourself. -- (void)resizeSubviewsWithOldSize:(NSSize)oldBoundsSize { - RBSplitView* sv = [self splitView]; - if (sv) { - BOOL ishor = [sv isHorizontal]; - NSRect frame = [self frame]; - float dim = DIM(frame.size); - float other = OTHER(frame.size); -// We resize subviews only when we're inside the subview's limits and the containing splitview's limits. - animationData* anim = [self RB___animationData:NO resize:NO]; - if ((dim>=(anim&&!anim->resizing?anim->dimension:minDimension))&&(dim<=maxDimension)&&(other>=[sv minDimension])&&(other<=[sv maxDimension])) { - if (notInLimits) { -// The subviews can be resized, so we restore the saved size. - oldBoundsSize = savedSize; - } -// We save the size every time the subview's subviews are resized within the limits. - notInLimits = NO; - savedSize = frame.size; - [super resizeSubviewsWithOldSize:oldBoundsSize]; - } else { - notInLimits = YES; - } - } -} - -// This method is used internally when a divider is dragged. It tries to change the subview's dimension -// and returns the actual change, collapsing or expanding whenever possible. You usually won't need -// to call this directly. -- (float)changeDimensionBy:(float)increment mayCollapse:(BOOL)mayCollapse move:(BOOL)move { - RBSplitView* sv = [self splitView]; - if (!sv||(fabsf(increment)<1.0)) { - return 0.0; - } - BOOL ishor = [sv isHorizontal]; - NSRect frame = [self frame]; - float olddim = DIM(frame.size); - float newdim = MAX(0.0,olddim+increment); - if (newdimolddim) { - if (olddim<1.0) { -// Expand if needed. - if (newdim>(minDimension*(0.5+HYSTERESIS))) { - newdim = MAX(newdim,[self RB___expandAndSetToMinimum:YES]); - } else { - return 0.0; - } - } - if (newdim>maxDimension) { - newdim = maxDimension; - } - } - if ((int)newdim!=(int)olddim) { -// The dimension has changed. - increment = newdim-olddim; - DIM(frame.size) = newdim; - if (move) { - DIM(frame.origin) -= increment; - } -// We call super instead of self here to postpone adjusting subviews for nested splitviews. -// [super setFrameSize:frame.size]; - [super setFrame:frame]; - [sv RB___setMustClearFractions]; - [sv setMustAdjust]; - } - return newdim-olddim; -} - -// This convenience method returns the number of subviews (surprise!) -- (unsigned)numberOfSubviews { - return [[self subviews] count]; -} - -// We return the deepest subview that's hit by aPoint. We also check with the delegate if aPoint is -// within an alternate drag view. -- (NSView*)hitTest:(NSPoint)aPoint { - RBSplitView* sv = [self splitView]; - if ([self mouse:aPoint inRect:[self frame]]) { - id delegate = [sv delegate]; - if ([delegate respondsToSelector:@selector(splitView:dividerForPoint:inSubview:)]) { - actDivider = [delegate splitView:sv dividerForPoint:aPoint inSubview:self]; - if ((int)actDivider<(int)([sv RB___numberOfSubviews]-1)) { - return self; - } - } - actDivider = NSNotFound; - NSView* result = [super hitTest:aPoint]; - canDragWindow = ![result isOpaque]; - return result; - } - return nil; -} - -// This method handles clicking and dragging in an empty portion of the subview, or in an alternate -// drag view as designated by the delegate. -- (void)mouseDown:(NSEvent*)theEvent { - NSWindow* window = [self window]; - NSPoint where = [theEvent locationInWindow]; - if (actDivider=WAYOUT) { -// The subview was collapsed when encoded, so we correct the origin and collapse it. - BOOL ishor = [self splitViewIsHorizontal]; - previous.origin.x -= WAYOUT; - DIM(previous.size) = 0.0; - [self setFrameOrigin:previous.origin]; - [self setFrameSize:previous.size]; - } - previous = NSZeroRect; - if ([coder allowsKeyedCoding]) { - [self setIdentifier:[coder decodeObjectForKey:@"identifier"]]; - tag = [coder decodeIntForKey:@"tag"]; - minDimension = [coder decodeFloatForKey:@"minDimension"]; - maxDimension = [coder decodeFloatForKey:@"maxDimension"]; - fraction = [coder decodeDoubleForKey:@"fraction"]; - canCollapse = [coder decodeBoolForKey:@"canCollapse"]; - } else { - [self setIdentifier:[coder decodeObject]]; - [coder decodeValueOfObjCType:@encode(typeof(tag)) at:&tag]; - [coder decodeValueOfObjCType:@encode(typeof(minDimension)) at:&minDimension]; - [coder decodeValueOfObjCType:@encode(typeof(maxDimension)) at:&maxDimension]; - [coder decodeValueOfObjCType:@encode(typeof(fraction)) at:&fraction]; - [coder decodeValueOfObjCType:@encode(typeof(canCollapse)) at:&canCollapse]; - } - } - return self; -} - -@end - -@implementation RBSplitSubview (RB___SubviewAdditions) - -// This hides/shows the subview without calling adjustSubview. -- (void)RB___setHidden:(BOOL)flag { - [super setHidden:flag]; -} - -// This internal method returns the current animationData. It will always return nil if -// the receiver isn't the current owner and some other subview is already being animated. -// Otherwise, if the parameter is YES, a new animation will be started (or the current -// one will be restarted). -- (animationData*)RB___animationData:(BOOL)start resize:(BOOL)resize { - if (currentAnimation&&(currentAnimation->owner!=self)) { -// There already is an animation in progress on some other subview. - return nil; - } - if (start) { -// We want to start (or restart) an animation. - RBSplitView* sv = [self splitView]; - if (sv) { - float dim = [self dimension]; -// First assume the default time, then ask the delegate. - NSTimeInterval total = dim*(0.2/150.0); - id delegate = [sv delegate]; - if ([delegate respondsToSelector:@selector(splitView:willAnimateSubview:withDimension:)]) { - total = [delegate splitView:sv willAnimateSubview:self withDimension:dim]; - } -// No use animating anything shorter than the frametime. - if (total>FRAMETIME) { - if (!currentAnimation) { - currentAnimation = (animationData*)malloc(sizeof(animationData)); - } - if (currentAnimation) { - currentAnimation->owner = self; - currentAnimation->stepsDone = 0; - currentAnimation->elapsedTime = 0.0; - currentAnimation->dimension = dim; - currentAnimation->collapsing = ![self isCollapsed]; - currentAnimation->totalTime = total; - currentAnimation->finishTime = [NSDate timeIntervalSinceReferenceDate]+total; - currentAnimation->resizing = resize; - [sv RB___setDragging:YES]; - } - } else if (currentAnimation) { - free(currentAnimation); - currentAnimation = NULL; - } - } - } - return currentAnimation; -} - -// This internal method steps the animation to the next frame. -- (void)RB___stepAnimation { - NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate]; - animationData* anim = [self RB___animationData:NO resize:NO]; - if (anim) { - RBSplitView* sv = [self splitView]; - NSTimeInterval remain = anim->finishTime-now; - NSRect frame = [self frame]; - BOOL ishor = [sv isHorizontal]; -// Continuing animation only makes sense if we still have at least FRAMETIME available. - if (remain>=FRAMETIME) { - float dim = DIM(frame.size); - float avg = anim->elapsedTime; -// We try to keep a record of how long it takes, on the average, to resize and adjust -// one animation frame. - if (anim->stepsDone) { - avg /= anim->stepsDone; - } - NSTimeInterval delay = MIN(0.0,FRAMETIME-avg); -// We adjust the new dimension proportionally to how much of the designated time has passed. - dim = floorf(anim->dimension*(remain-avg)/anim->totalTime); - if (dim>4.0) { - if (!anim->collapsing) { - dim = anim->dimension-dim; - } - DIM(frame.size) = dim; - [self RB___setFrame:frame withFraction:0.0 notify:NO]; - [sv adjustSubviews]; - [self display]; - anim->elapsedTime += [NSDate timeIntervalSinceReferenceDate]-now; - ++anim->stepsDone; -// Schedule a timer to do the next animation step. - [self performSelector:@selector(RB___stepAnimation) withObject:nil afterDelay:delay inModes:[NSArray arrayWithObjects:NSDefaultRunLoopMode,NSModalPanelRunLoopMode, - NSEventTrackingRunLoopMode,nil]]; - return; - } - } -// We're finished, either collapse or expand entirely now. - if (anim->collapsing) { - DIM(frame.size) = 0.0; - [self RB___finishCollapse:frame withFraction:anim->dimension/[sv RB___dimensionWithoutDividers]]; - } else { - float savemin,savemax; - float dim = [self RB___setMinAndMaxTo:anim->dimension savingMin:&savemin andMax:&savemax]; - DIM(frame.size) = dim; - [self RB___finishExpand:frame withFraction:0.0]; - minDimension = savemin; - maxDimension = savemax; - } - } -} - -// This internal method stops the animation, if the receiver is being animated. It will -// return YES if the animation was stopped. -- (BOOL)RB___stopAnimation { - if (currentAnimation&&(currentAnimation->owner==self)) { - [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(RB___stepAnimation) object:nil]; - free(currentAnimation); - currentAnimation = NULL; - [[self splitView] RB___setDragging:NO]; - return YES; - } - return NO; -} - -// This internal method returns the actual visible dimension of the subview. Differs from -dimension in -// that it returns 0.0 if the subview is collapsed. -- (float)RB___visibleDimension { - BOOL ishor = [self splitViewIsHorizontal]; - NSRect frame = [self frame]; - return MAX(0.0,DIM(frame.size)); -} - -// This pair of internal methods is used only inside -[RBSplitView adjustSubviews] to copy subview data -// from and to that method's internal cache. -- (void)RB___copyIntoCache:(subviewCache*)cache { - cache->sub = self; - cache->rect = [self frame]; - cache->size = [self RB___visibleDimension]; - cache->fraction = fraction; - cache->constrain = NO; -} - -- (void)RB___updateFromCache:(subviewCache*)cache withTotalDimension:(float)value { - float dim = [self RB___visibleDimension]; - if (cache->size>=1.0) { -// New state is not collapsed. - if (dim>=1.0) { -// Old state was not collapsed, so we just change the frame. - [self RB___setFrame:cache->rect withFraction:cache->fraction notify:YES]; - } else { -// Old state was collapsed, so we expand it. - [self RB___finishExpand:cache->rect withFraction:cache->fraction]; - } - } else { -// New state is collapsed. - if (dim>=1.0) { -// Old state was not collapsed, so we clear first responder and change the frame. - [self RB___clearResponder]; - [self RB___finishCollapse:cache->rect withFraction:dim/value]; - } else { -// It was collapsed already, but the frame may have changed, so we set it. - [self RB___setFrame:cache->rect withFraction:cache->fraction notify:YES]; - } - } -} - -// This internal method sets minimum and maximum values to the same value, saves the old values, -// and returns the new value (which will be limited to the old values). -- (float)RB___setMinAndMaxTo:(float)value savingMin:(float*)oldmin andMax:(float*)oldmax { - *oldmin = [self minDimension]; - *oldmax = [self maxDimension]; - if (value<*oldmin) { - value = *oldmin; - } - if (value>*oldmax) { - value = *oldmax; - } - minDimension = maxDimension = value; - return value; -} - -// This internal method tries to clear the first responder, if the current responder is a descendant of -// the receiving subview. If so, it will set first responder to nil, redisplay the former responder and -// return YES. Returns NO otherwise. -- (BOOL)RB___clearResponder { - NSWindow* window = [self window]; - if (window) { - NSView* responder = (NSView*)[window firstResponder]; - if (responder&&[responder respondsToSelector:@selector(isDescendantOf:)]) { - if ([responder isDescendantOf:self]) { - if ([window makeFirstResponder:nil]) { - [responder display]; - return YES; - } - } - } - } - return NO; -} - -// This internal method collapses a subview. -// It returns the negative of the size of the subview before collapsing, or 0.0 if it wasn't collapsed. -- (float)RB___collapse { - float result = 0.0; - if (![self isCollapsed]) { - RBSplitView* sv = [self splitView]; - if (sv&&[self canCollapse]) { - [self RB___clearResponder]; - NSRect frame = [self frame]; - BOOL ishor = [sv isHorizontal]; - result = DIM(frame.size); -// For collapsed views, fraction will contain the fraction of the dimension previously occupied - DIM(frame.size) = 0.0; - [self RB___finishCollapse:frame withFraction:result/[sv RB___dimensionWithoutDividers]]; - } - } - return -result; -} - -// This internal method finishes the collapse of a subview, stopping the animation if -// there is one, and calling the delegate method if there is one. -- (void)RB___finishCollapse:(NSRect)rect withFraction:(double)value { - RBSplitView* sv = [self splitView]; - BOOL finish = [self RB___stopAnimation]; - [self RB___setFrame:rect withFraction:value notify:YES]; - [sv RB___setMustClearFractions]; - if (finish) { - [self display]; - } - id delegate = [sv delegate]; - if ([delegate respondsToSelector:@selector(splitView:didCollapse:)]) { - [delegate splitView:sv didCollapse:self]; - } -} - -// This internal method expands a subview. setToMinimum will usually be YES during a divider drag. -// It returns the size of the subview after expanding, or 0.0 if it wasn't expanded. -- (float)RB___expandAndSetToMinimum:(BOOL)setToMinimum { - float result = 0.0; - RBSplitView* sv = [self splitView]; - if (sv&&[self isCollapsed]) { - NSRect frame = [super frame]; - double frac = fraction; - BOOL ishor = [sv isHorizontal]; - if (setToMinimum) { - result = DIM(frame.size) = minDimension; - } else { - result = [sv RB___dimensionWithoutDividers]*frac; -// We need to apply a compensation factor for proportional resizing in adjustSubviews. - float newdim = floorf((frac>=1.0)?result:result/(1.0-frac)); - DIM(frame.size) = newdim; - result = floorf(result); - } - [self RB___finishExpand:frame withFraction:0.0]; - } - return result; -} - -// This internal method finishes the the expansion of a subview, stopping the animation if -// there is one, and calling the delegate method if there is one. -- (void)RB___finishExpand:(NSRect)rect withFraction:(double)value { - RBSplitView* sv = [self splitView]; - BOOL finish = [self RB___stopAnimation]; - [self RB___setFrame:rect withFraction:value notify:YES]; - [sv RB___setMustClearFractions]; - if (finish) { - [self display]; - } - id delegate = [sv delegate]; - if ([delegate respondsToSelector:@selector(splitView:didExpand:)]) { - [delegate splitView:sv didExpand:self]; - } -} - -// These internal methods set the subview's frame or size, and also store a fraction value -// which is used to ensure repeatability when the whole split view is resized. -- (void)RB___setFrame:(NSRect)rect withFraction:(double)value notify:(BOOL)notify { - RBSplitView* sv = [self splitView]; - id delegate = nil; - if (notify) { - delegate = [sv delegate]; -// If the delegate method isn't implemented, we ignore the delegate altogether. - if ([delegate respondsToSelector:@selector(splitView:changedFrameOfSubview:from:to:)]) { -// If the rects are equal, the delegate isn't called. - if (NSEqualRects(previous,rect)) { - delegate = nil; - } - } else { - delegate = nil; - } - } - [sv setMustAdjust]; - [self setFrame:rect]; - fraction = value; - [delegate splitView:sv changedFrameOfSubview:self from:previous to:rect]; - previous = delegate?rect:NSZeroRect; -} - -- (void)RB___setFrameSize:(NSSize)size withFraction:(double)value { - [[self splitView] setMustAdjust]; - [self setFrameSize:size]; - fraction = value; -} - -// This internal method gets the fraction value. -- (double)RB___fraction { - return fraction; -} - -@end - -#endif // MM_ENABLE_PLUGINS diff --git a/src/MacVim/RBSplitView.h b/src/MacVim/RBSplitView.h deleted file mode 100644 index 0c786c2b09..0000000000 --- a/src/MacVim/RBSplitView.h +++ /dev/null @@ -1,225 +0,0 @@ -// -// RBSplitView.h version 1.1.4 -// RBSplitView -// -// Created by Rainer Brockerhoff on 24/09/2004. -// Copyright 2004-2006 Rainer Brockerhoff. -// Some Rights Reserved under the Creative Commons Attribution License, version 2.5, and/or the MIT License. -// - -#import "RBSplitSubview.h" - -// These values are used to handle the various cursor types. -typedef enum { - RBSVHorizontalCursor=0, // appears over horizontal dividers - RBSVVerticalCursor, // appears over vertical dividers - RBSV2WayCursor, // appears over two-way thumbs - RBSVDragCursor, // appears while dragging - RBSVCursorTypeCount -} RBSVCursorType; - -@interface RBSplitView : RBSplitSubview { -// Subclasses normally should use setter methods instead of changing instance variables by assignment. -// Most getter methods simply return the corresponding instance variable, so with some care, subclasses -// could reference them directly. - IBOutlet id delegate; // The delegate (may be nil). - NSString* autosaveName; // This name is used for storing subview proportions in user defaults. - NSColor* background; // The color used to paint the view's background (may be nil). - NSImage* divider; // The image used for the divider "dimple". - NSRect* dividers; // A C array of NSRects, one for each divider. - float dividerThickness; // Actual divider width; should be an integer and at least 1.0. - BOOL mustAdjust; // Set internally if the subviews need to be adjusted. - BOOL mustClearFractions; // Set internally if fractions should be cleared before adjusting. - BOOL isHorizontal; // The divider's orientation; default is vertical. - BOOL canSaveState; // Set internally to allow saving subview state. - BOOL isCoupled; // If YES, take some parameters from the containing RBSplitView, if any. - BOOL isAdjusting; // Set internally while the subviews are being adjusted. - BOOL isDragging; // Set internally while in a drag loop. - BOOL isInScrollView; // Set internally if directly contained in an NSScrollView. -} - -// These class methods get and set the cursor used for each type. -// Pass in nil to reset to the default cursor for that type. -+ (NSCursor*)cursor:(RBSVCursorType)type; -+ (void)setCursor:(RBSVCursorType)type toCursor:(NSCursor*)cursor; - -// This class method clears the saved state for a given autosave name from the defaults. -+ (void)removeStateUsingName:(NSString*)name; - -// This class method returns the actual key used to store autosave data in the defaults. -+ (NSString*)defaultsKeyForName:(NSString*)name isHorizontal:(BOOL)orientation; - -// Sets and gets the autosaveName; this will be the key used to store the subviews' proportions -// in the user defaults. Default is @"", which doesn't save anything. Set flag to YES to set -// unique names for nested subviews. You are responsible for avoiding duplicates. -- (void)setAutosaveName:(NSString*)aString recursively:(BOOL)flag; -- (NSString*)autosaveName; - -// Saves the current state of the subviews if there's a valid autosave name set. If the argument -// is YES, it's then also called recursively for nested RBSplitViews. Returns YES if successful. -- (BOOL)saveState:(BOOL)recurse; - -// Restores the saved state of the subviews if there's a valid autosave name set. If the argument -// is YES, it's first called recursively for nested RBSplitViews. Returns YES if successful. -// You need to call adjustSubviews after calling this. -- (BOOL)restoreState:(BOOL)recurse; - -// Returns a string encoding the current state of all direct subviews. Does not check for nesting. -- (NSString*)stringWithSavedState; - -// Readjusts all direct subviews according to the encoded string parameter. The number of subviews -// must match. Returns YES if successful. Does not check for nesting. -- (BOOL)setStateFromString:(NSString*)aString; - -// Returns an array with complete state information for the receiver and all subviews, taking -// nesting into account. Don't store this array in a file, as its format might change in the -// future; this is for taking a state snapshot and later restoring it with setStatesFromArray. -- (NSArray*)arrayWithStates; - -// Restores the state of the receiver and all subviews. The array must have been produced by a -// previous call to arrayWithStates. Returns YES if successful. This will fail if you have -// added or removed subviews in the meantime! -// You need to call adjustSubviews after calling this. -- (BOOL)setStatesFromArray:(NSArray*)array; - -// This is the designated initializer for creating RBSplitViews programmatically. -- (id)initWithFrame:(NSRect)frame; - -// This convenience initializer adds any number of subviews and adjusts them proportionally. -- (id)initWithFrame:(NSRect)frame andSubviews:(unsigned)count; - -// Sets and gets the delegate. (Delegates aren't retained.) See further down for delegate methods. -- (void)setDelegate:(id)anObject; -- (id)delegate; - -// Returns a subview which has a certain identifier string, or nil if there's none -- (RBSplitSubview*)subviewWithIdentifier:(NSString*)anIdentifier; - -// Returns the subview at a certain position. Returns nil if the position is invalid. -- (RBSplitSubview*)subviewAtPosition:(unsigned)position; - -// Adds a subview at a certain position. -- (void)addSubview:(NSView*)aView atPosition:(unsigned)position; - -// Sets and gets the divider thickness, which should be a positive integer or zero. -// Setting the divider image also resets this automatically, so you would call this -// only if you want the divider to be larger or smaller than the image. Zero means that -// the image dimensions will be used. -- (void)setDividerThickness:(float)thickness; -- (float)dividerThickness; - -// Sets and gets the divider image. The default image can also be set in Interface Builder, so usually -// there's no need to call this. Passing in nil means that the default divider thickness will be zero, -// and no mouse events will be processed, so that the dividers can be moved only programmatically. -- (void)setDivider:(NSImage*)image; -- (NSImage*)divider; - -// Sets and gets the view background. The default is nil, meaning no background is -// drawn and the view and its subviews are considered transparent. -- (void)setBackground:(NSColor*)color; -- (NSColor*)background; - -// Sets and gets the orientation. This uses the same convention as NSSplitView: vertical means the -// dividers are vertical, but the subviews are in a horizontal row. Sort of counter-intuitive, yes. -- (void)setVertical:(BOOL)flag; -- (BOOL)isVertical; -- (BOOL)isHorizontal; - -// Call this to force adjusting the subviews before display. Called automatically if anything -// relevant is changed. -- (void)setMustAdjust; - -// Returns YES if there's a pending adjustment. -- (BOOL)mustAdjust; - -// Returns YES if we're in a dragging loop. -- (BOOL)isDragging; - -// Returns YES if the view is directly contained in an NSScrollView. -- (BOOL)isInScrollView; - -// Call this to recalculate all subview dimensions. Normally this is done automatically whenever -// something relevant is changed, so you rarely will need to call this explicitly. -- (void)adjustSubviews; - -// This method should be called only from within the splitView:wasResizedFrom:to: delegate method -// to keep some specific subview the same size. -- (void)adjustSubviewsExcepting:(RBSplitSubview*)excepting; - -// This method draws dividers. You should never call it directly but you can override it when -// subclassing, if you need custom dividers. -- (void)drawDivider:(NSImage*)anImage inRect:(NSRect)rect betweenView:(RBSplitSubview*)leading andView:(RBSplitSubview*)trailing; - -@end - -// The following methods are optionally implemented by the delegate. - -@interface NSObject(RBSplitViewDelegate) - -// The delegate can override a subview's ability to collapse by implementing this method. -// Return YES to allow collapsing. If this is implemented, the subviews' built-in -// 'collapsed' flags are ignored. -- (BOOL)splitView:(RBSplitView*)sender canCollapse:(RBSplitSubview*)subview; - -// The delegate can alter the divider's appearance by implementing this method. -// Before calling this, the divider is filled with the background, and afterwards -// the divider image is drawn into the returned rect. If imageRect is empty, no -// divider image will be drawn, because there are nested RBSplitViews. Return -// NSZeroRect to suppress the divider image. Return imageRect to use the default -// location for the image, or change its origin to place the image elsewhere. -// You could also draw the divider yourself at this point and return NSZeroRect. -- (NSRect)splitView:(RBSplitView*)sender willDrawDividerInRect:(NSRect)dividerRect betweenView:(RBSplitSubview*)leading andView:(RBSplitSubview*)trailing withProposedRect:(NSRect)imageRect; - -// These methods are called after a subview is completely collapsed or expanded. adjustSubviews may or may not -// have been called, however. -- (void)splitView:(RBSplitView*)sender didCollapse:(RBSplitSubview*)subview; -- (void)splitView:(RBSplitView*)sender didExpand:(RBSplitSubview*)subview; - -// These methods are called just before and after adjusting subviews. -- (void)willAdjustSubviews:(RBSplitView*)sender; -- (void)didAdjustSubviews:(RBSplitView*)sender; - -// This method will be called after a RBSplitView is resized with setFrameSize: but before -// adjustSubviews is called on it. -- (void)splitView:(RBSplitView*)sender wasResizedFrom:(float)oldDimension to:(float)newDimension; - -// This method will be called when a divider is double-clicked and both leading and trailing -// subviews can be collapsed. Return either of the parameters to collapse that subview, or nil -// to collapse neither. If not implemented, the smaller subview will be collapsed. -- (RBSplitSubview*)splitView:(RBSplitView*)sender collapseLeading:(RBSplitSubview*)leading orTrailing:(RBSplitSubview*)trailing; - -// This method will be called when a cursor rect is being set (inside resetCursorRects). The -// proposed rect is passed in. Return the actual rect, or NSZeroRect to suppress cursor setting -// for this divider. This won't be called for two-axis thumbs, however. The rects are in -// sender's local coordinates. -- (NSRect)splitView:(RBSplitView*)sender cursorRect:(NSRect)rect forDivider:(unsigned int)divider; - -// This method will be called whenever a mouse-down event is received in a divider. Return YES to have -// the event handled by the split view, NO if you wish to ignore it or handle it in the delegate. -- (BOOL)splitView:(RBSplitView*)sender shouldHandleEvent:(NSEvent*)theEvent inDivider:(unsigned int)divider betweenView:(RBSplitSubview*)leading andView:(RBSplitSubview*)trailing; - -// This method will be called just before a subview will be collapsed or expanded with animation. -// Return the approximate time the animation should take, or 0.0 to disallow animation. -// If not implemented, it will use the default of 0.2 seconds per 150 pixels. -- (NSTimeInterval)splitView:(RBSplitView*)sender willAnimateSubview:(RBSplitSubview*)subview withDimension:(float)dimension; - -// This method will be called whenever a subview's frame is changed, usually from inside adjustSubviews' final loop. -// You'd normally use this to move some auxiliary view to keep it aligned with the subview. -- (void)splitView:(RBSplitView*)sender changedFrameOfSubview:(RBSplitSubview*)subview from:(NSRect)fromRect to:(NSRect)toRect; - -// This method is called whenever the event handlers want to check if some point within the RBSplitSubview -// should act as an alternate drag view. Usually, the delegate will check the point (which is in sender's -// local coordinates) against the frame of one or several auxiliary views, and return a valid divider number. -// Returning NSNotFound means the point is not valid. -- (unsigned int)splitView:(RBSplitView*)sender dividerForPoint:(NSPoint)point inSubview:(RBSplitSubview*)subview; - -// This method is called continuously while a divider is dragged, just before the leading subview is resized. -// Return NO to resize the trailing view by the same amount, YES to resize the containing window by the same amount. -- (BOOL)splitView:(RBSplitView*)sender shouldResizeWindowForDivider:(unsigned int)divider betweenView:(RBSplitSubview*)leading andView:(RBSplitSubview*)trailing willGrow:(BOOL)grow; - -// This method is called by each subview's drawRect: method, just after filling it with the background color but -// before the contained subviews are drawn. Usually you would use this to draw a frame inside the subview. -- (void)splitView:(RBSplitView*)sender willDrawSubview:(RBSplitSubview*)subview inRect:(NSRect)rect; - -@end - diff --git a/src/MacVim/RBSplitView.m b/src/MacVim/RBSplitView.m deleted file mode 100644 index 0e11d5bdc3..0000000000 --- a/src/MacVim/RBSplitView.m +++ /dev/null @@ -1,1736 +0,0 @@ -// -// RBSplitView.m version 1.1.4 -// RBSplitView -// -// Created by Rainer Brockerhoff on 24/09/2004. -// Copyright 2004-2006 Rainer Brockerhoff. -// Some Rights Reserved under the Creative Commons Attribution License, version 2.5, and/or the MIT License. -// -#ifdef MM_ENABLE_PLUGINS - -#import "RBSplitView.h" -#import "RBSplitViewPrivateDefines.h" - -// Please don't remove this copyright notice! -static const unsigned char RBSplitView_Copyright[] __attribute__ ((used)) = - "RBSplitView 1.1.4 Copyright(c)2004-2006 by Rainer Brockerhoff ."; - -// This vector keeps currently used cursors. nil means the default cursor. -static NSCursor* cursors[RBSVCursorTypeCount] = {nil}; - -// Our own fMIN and fMAX -static inline float fMIN(float a,float b) { - return ab?a:b; -} - -@implementation RBSplitView - -// These class methods get and set the cursor used for each type. -// Pass in nil to reset to the default cursor for that type. -+ (NSCursor*)cursor:(RBSVCursorType)type { - if ((type>=0)&&(type=0)&&(type1)&&([[parts objectAtIndex:0] intValue]==subcount)&&(k==subcount)) { - int i; - NSRect frame = [self frame]; - BOOL ishor = [self isHorizontal]; - for (i=0;i