Skip to content

Commit

Permalink
format syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimm committed Jan 18, 2009
1 parent c3c482c commit cf5884a
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 73 deletions.
2 changes: 1 addition & 1 deletion Commands/ExtendedPopUp/DocPopup.m
Expand Up @@ -18,7 +18,7 @@ + (id)showWithContent:(NSString*)content atLocation:(NSPoint)point transparent:(
return tip;
}

-(id)init
- (id)init
{
if( (self = [super init]) ) {

Expand Down
2 changes: 1 addition & 1 deletion Commands/ExtendedPopUp/MenuWindowView.h
Expand Up @@ -31,5 +31,5 @@
- (id)delegate;
- (void)setDelegate:(id)del;
- (BOOL)TMDcanHandleEvent:(NSEvent*)anEvent;
- (void) arrangeInitialSelection;
- (void)arrangeInitialSelection;
@end
124 changes: 62 additions & 62 deletions Commands/ExtendedPopUp/MenuWindowView.mm
Expand Up @@ -14,10 +14,10 @@
#define TEXT_INDENT 25

CGRect NSRectToCGRect(NSRect nsrect) {
return (*(CGRect *)&(nsrect));
return (*(CGRect *)&(nsrect));
}
NSRect NSRectFromCGRect(CGRect cgrect) {
return (*(NSRect *)&(cgrect));
return (*(NSRect *)&(cgrect));
}

int cap (int min, int val, int max)
Expand All @@ -34,53 +34,53 @@ @implementation NSBezierPath (BezierPathQuartzUtilities)
- (CGPathRef)quartzPath
{
int i, numElements;

// Need to begin a path here.
CGPathRef immutablePath = NULL;

// Then draw the path elements.
numElements = [self elementCount];
if (numElements > 0)
{
CGMutablePathRef path = CGPathCreateMutable();
NSPoint points[3];
BOOL didClosePath = YES;

for (i = 0; i < numElements; i++)
{
switch ([self elementAtIndex:i associatedPoints:points])
{
case NSMoveToBezierPathElement:
CGPathMoveToPoint(path, NULL, points[0].x, points[0].y);
break;

CGPathMoveToPoint(path, NULL, points[0].x, points[0].y);
break;
case NSLineToBezierPathElement:
CGPathAddLineToPoint(path, NULL, points[0].x, points[0].y);
didClosePath = NO;
break;

CGPathAddLineToPoint(path, NULL, points[0].x, points[0].y);
didClosePath = NO;
break;
case NSCurveToBezierPathElement:
CGPathAddCurveToPoint(path, NULL, points[0].x, points[0].y,
points[1].x, points[1].y,
points[2].x, points[2].y);
didClosePath = NO;
break;

CGPathAddCurveToPoint(path, NULL, points[0].x, points[0].y,
points[1].x, points[1].y,
points[2].x, points[2].y);
didClosePath = NO;
break;
case NSClosePathBezierPathElement:
CGPathCloseSubpath(path);
didClosePath = YES;
break;
CGPathCloseSubpath(path);
didClosePath = YES;
break;
}
}

// Be sure the path is closed or Quartz may not do valid hit detection.
if (!didClosePath)
CGPathCloseSubpath(path);

immutablePath = CGPathCreateCopy(path);
CGPathRelease(path);
}

return immutablePath;
}
@end
Expand All @@ -100,20 +100,20 @@ + (NSBezierPath *)bezierPathWithRoundedRect: (NSRect) aRect cornerRadius: (doubl
{
cRadius = lesserDim / 2;
}

//these points describe the rectangle as start and stop points of the
//arcs making up its corners --points c, e, & g are implicit endpoints of arcs
//and are unnecessary
NSPoint a = NSMakePoint( 0, cRadius ), b = NSMakePoint( 0, height - cRadius ),
d = NSMakePoint( width - cRadius, height ), f = NSMakePoint( width, cRadius ),
h = NSMakePoint( cRadius, 0 );

d = NSMakePoint( width - cRadius, height ), f = NSMakePoint( width, cRadius ),
h = NSMakePoint( cRadius, 0 );
//these points describe the center points of the corner arcs
NSPoint cA = NSMakePoint( cRadius, height - cRadius ),
cB = NSMakePoint( width - cRadius, height - cRadius ),
cC = NSMakePoint( width - cRadius, cRadius ),
cD = NSMakePoint( cRadius, cRadius );
cB = NSMakePoint( width - cRadius, height - cRadius ),
cC = NSMakePoint( width - cRadius, cRadius ),
cD = NSMakePoint( cRadius, cRadius );

//start
NSBezierPath *bp = [NSBezierPath bezierPath];
[bp moveToPoint: a ];
Expand All @@ -126,12 +126,12 @@ + (NSBezierPath *)bezierPathWithRoundedRect: (NSRect) aRect cornerRadius: (doubl
[bp lineToPoint: h ];
[bp appendBezierPathWithArcWithCenter: cD radius: cRadius startAngle:270 endAngle:180 clockwise: YES];
[bp closePath];

//Transform path to rectangle's origin
NSAffineTransform *transform = [NSAffineTransform transform];
[transform translateXBy: left yBy: bottom];
[bp transformUsingAffineTransform: transform];

return bp; //it's already been autoreleased
}
@end
Expand All @@ -150,7 +150,7 @@ @implementation MenuWindowView
- (id)initWithDataSource:(id)theDataSource
{
dataSource = theDataSource;

if(self = [self initWithFrame:NSZeroRect])
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewFrameDidChange:) name:NSViewFrameDidChangeNotification object:self];
Expand Down Expand Up @@ -187,15 +187,15 @@ - (float)maxItemWidth
tinfo.options = kHIThemeTextBoxOptionNone;
tinfo.truncationPosition = kHIThemeTextTruncationEnd;
tinfo.truncationMaxLines = 1;

if([[self items] count]>0)
{
for(int i=0; i<[[self items] count]; i++)
{
NSString* text = [[[self items] objectAtIndex:i] objectForKey:@"display"];
float width;
HIThemeGetTextDimensions((CFStringRef)text, 600, &tinfo, &width, NULL, NULL);

if(width > maxWidth)
maxWidth = width;
}
Expand Down Expand Up @@ -226,29 +226,29 @@ - (NSArray*)items

- (void)drawRect:(NSRect)rect
{

CGContextRef cgContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
HIRect bounds = NSRectToCGRect([self bounds]);

// TODO switch to HIThemeGetMenuBackgroundShape() for this
CGPathRef menuPath = [[NSBezierPath bezierPathWithRoundedRect:[self bounds] cornerRadius:5.0] quartzPath];

// Draw the menu background, clipped to the rounded rectangle
HIThemeMenuDrawInfo drawInfo;
drawInfo.version = 0;
drawInfo.menuType = kThemeMenuTypePullDown;
CGContextAddPath(cgContext, menuPath);
CGContextClip(cgContext);
HIThemeDrawMenuBackground(&bounds, &drawInfo, cgContext, kHIThemeOrientationNormal);

// Add a border around the menu
CGContextAddPath(cgContext, menuPath);
CGContextSetRGBStrokeColor(cgContext, 0.8, 0.8, 0.8, 1.0);
CGContextSetLineWidth(cgContext, 1.0);
CGContextStrokePath(cgContext);

float y = [self bounds].size.height - [self rowHeight];

if([self showUpArrow])
{
HIRect arrowBounds = bounds;
Expand All @@ -275,7 +275,7 @@ - (void)drawRect:(NSRect)rect
HIThemeDrawMenuItem(&hiRowRect, &hiRowRect, &aMenuItemDrawInfo, cgContext, kHIThemeOrientationNormal, NULL);
hiRowRect.origin.x += TEXT_INDENT;
hiRowRect.size.width -= TEXT_INDENT;

HIThemeTextInfo tinfo;
tinfo.version = 1;
tinfo.state = kThemeMenuActive;
Expand All @@ -285,18 +285,18 @@ - (void)drawRect:(NSRect)rect
tinfo.options = kHIThemeTextBoxOptionNone;
tinfo.truncationPosition = kHIThemeTextTruncationEnd;
tinfo.truncationMaxLines = 1;

NSFont* font = [NSFont fontWithName:[[NSUserDefaults standardUserDefaults] stringForKey:@"OakTextViewNormalFontName"] ?: [[NSFont userFixedPitchFontOfSize:12.0] fontName]
size:[[NSUserDefaults standardUserDefaults] integerForKey:@"OakTextViewNormalFontSize"] ?: 12 ];
size:[[NSUserDefaults standardUserDefaults] integerForKey:@"OakTextViewNormalFontSize"] ?: 12 ];
[text drawInRect:NSRectFromCGRect(hiRowRect)
withAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
((aMenuItemDrawInfo.state == kThemeMenuSelected) ? [NSColor selectedMenuItemTextColor] : [NSColor blackColor]), NSForegroundColorAttributeName,
font, NSFontAttributeName,
nil]];

withAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
((aMenuItemDrawInfo.state == kThemeMenuSelected) ? [NSColor selectedMenuItemTextColor] : [NSColor blackColor]), NSForegroundColorAttributeName,
font, NSFontAttributeName,
nil]];
y -= [self rowHeight];
}

if([self showDownArrow])
{
HIRect arrowBounds = bounds;
Expand All @@ -307,14 +307,14 @@ - (void)drawRect:(NSRect)rect
aMenuItemDrawInfo.state = kThemeMenuActive;
HIThemeDrawMenuItem(&arrowBounds, &arrowBounds, &aMenuItemDrawInfo, cgContext, kHIThemeOrientationNormal, NULL);
}

CGPathRelease(menuPath);
menuPath = NULL;
[self newSelectionOccured];

}

-(int)selectedRow {
- (int)selectedRow {
for(int i = visibleOffset; i < visibleOffset + visibleItemsCount; ++i)
{
NSDictionary* item = [[self items] objectAtIndex:i];
Expand Down Expand Up @@ -347,7 +347,7 @@ - (id)selectedItem;
return selectedItem;
}

- (void) arrangeInitialSelection
- (void)arrangeInitialSelection
{
selectedItem = [[self items] objectAtIndex:0];
[self setNeedsDisplay:YES];
Expand All @@ -366,7 +366,7 @@ - (void)mouseMoved:(NSEvent*)event
int newVisibleOffset = visibleOffset;
int index = ([self bounds].size.height - cursor.y) / [self rowHeight];
if(index < 0) return;

if([self showUpArrow])
{
if(index == 0)
Expand Down Expand Up @@ -409,7 +409,7 @@ - (BOOL)TMDcanHandleEvent:(NSEvent*)anEvent
{ NSHomeFunctionKey, -(INT_MAX >> 1) },
{ NSEndFunctionKey, +(INT_MAX >> 1) },
};

unichar keyCode = 0;
if([anEvent type] == NSScrollWheel)
keyCode = [anEvent deltaY] >= 0.0 ? NSUpArrowFunctionKey : NSDownArrowFunctionKey;
Expand All @@ -420,7 +420,7 @@ - (BOOL)TMDcanHandleEvent:(NSEvent*)anEvent
[self mouseMoved:anEvent];
return YES;
}

for(size_t i = 0; i < sizeofA(key_movements); ++i)
{
if(keyCode == key_movements[i].key)
Expand All @@ -439,12 +439,12 @@ - (BOOL)TMDcanHandleEvent:(NSEvent*)anEvent
return YES;
}
}

return NO;
}
- (void)newSelectionOccured{
if([[self delegate] respondsToSelector:@selector(viewDidChangeSelection)])
[[self delegate] viewDidChangeSelection];
if([[self delegate] respondsToSelector:@selector(viewDidChangeSelection)])
[[self delegate] viewDidChangeSelection];
}
- (id)delegate { return delegate; }
- (void)setDelegate:(id)del { delegate = del; }
Expand Down
17 changes: 8 additions & 9 deletions Commands/ExtendedPopUp/TMDIncrementalPopUpMenu.mm
Expand Up @@ -21,9 +21,9 @@ - (void)filter;
- (void)insertCommonPrefix;
- (void)completeAndInsertSnippet;
- (void)startReadingDocs;
- (void) stopProcess;
- (void) closeHTMLPopup;
-(void) writeNullTerminatedString:(NSString*)string;
- (void)stopProcess;
- (void)closeHTMLPopup;
- (void)writeNullTerminatedString:(NSString*)string;
@end

@implementation TMDIncrementalPopUpMenu
Expand Down Expand Up @@ -148,7 +148,7 @@ - (void)viewDidChangeSelection
}
}

-(void) writeNullTerminatedString:(NSString*)string
- (void)writeNullTerminatedString:(NSString*)string
{
@synchronized(outputHandle){
[outputHandle writeString:string];
Expand All @@ -157,14 +157,13 @@ -(void) writeNullTerminatedString:(NSString*)string
}
}

-(void) displayHTMLPopup:(NSString*)html
- (void)displayHTMLPopup:(NSString*)html
{
[html retain];
NSPoint pos = caretPos;
pos.x = pos.x + [self frame].size.width + 5;
[self closeHTMLPopup];
@synchronized(htmlTooltip){
if(![html isEqualToString:@""])
htmlTooltip = [DocPopup showWithContent:html atLocation:pos transparent: NO];
}
[html release];
Expand All @@ -179,7 +178,7 @@ - (void)startReadingDocs
[inputHandle readInBackgroundAndNotify];
}

- (void) getData: (NSNotification*)aNotification
- (void)getData: (NSNotification*)aNotification
{
NSData *data = [[aNotification userInfo] objectForKey:NSFileHandleNotificationDataItem];
// assuming there is no way to get zero length data unless EOF?
Expand Down Expand Up @@ -233,14 +232,14 @@ - (void) getData: (NSNotification*)aNotification
[inputHandle readInBackgroundAndNotify];
}

- (void) stopProcess
- (void)stopProcess
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSFileHandleReadCompletionNotification object: inputHandle];
[self closeHTMLPopup];
closeMe = YES;
}

-(void) closeHTMLPopup
- (void)closeHTMLPopup
{
@synchronized(htmlTooltip){
if(htmlTooltip != nil){
Expand Down

0 comments on commit cf5884a

Please sign in to comment.