Skip to content

Commit

Permalink
import CommitWindow sources
Browse files Browse the repository at this point in the history
  • Loading branch information
martinh committed Jul 8, 2012
1 parent ce6e15a commit 3dcd5a3
Show file tree
Hide file tree
Showing 25 changed files with 11,042 additions and 0 deletions.
46 changes: 46 additions & 0 deletions CommitWindow/CWTextView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// CWTextView.m
// CommitWindow
//
// Created by Chris Thomas on 3/7/05.
// Copyright 2005-2006 Chris Thomas. All rights reserved.
// MIT license.
//

#import <Cocoa/Cocoa.h>


@interface CWTextView : NSTextView
{
float fMinHeight;
float fMaxHeight;
float fMinWidth;
float fMaxWidth;

NSRect fInitialViewFrame;
NSPoint fInitialMousePoint;
BOOL fTrackingGrowBox;

BOOL fAllowGrowHorizontally;
BOOL fAllowGrowVertically;
}

- (BOOL)allowHorizontalResize;
- (void)setAllowHorizontalResize:(BOOL)newAllowGrowHorizontally;

- (BOOL)allowVerticalResize;
- (void)setAllowVerticalResize:(BOOL)newAllowGrowVertically;

- (float)maxWidth;
- (void)setMaxWidth:(float)newMaxWidth;

- (float)minWidth;
- (void)setMinWidth:(float)newMinWidth;

- (float)minHeight;
- (void)setMinHeight:(float)newMinHeight;

- (float)maxHeight;
- (void)setMaxHeight:(float)newMaxHeight;

@end
266 changes: 266 additions & 0 deletions CommitWindow/CWTextView.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
//
// CWTextView.m
// CommitWindow
//
// Created by Chris Thomas on 3/7/05.
// Copyright 2005-2006 Chris Thomas. All rights reserved.
// MIT license.
//

#import "CWTextView.h"

@implementation CWTextView

- (void) awakeFromNib
{
// Arbitrary factory settings
fMinHeight = 40.0f;
fMaxHeight = 32767.0f;
fMinWidth = 100.0f;
fMaxWidth = 32767.0f;

fAllowGrowHorizontally = NO;
fAllowGrowVertically = YES;
}

#if 0
#pragma mark -
#pragma mark Do not eat the enter key
#endif

- (void) keyDown:(NSEvent *)event
{
// don't let the textview eat the enter key
if( [[event characters] isEqualToString:@"\x03"] )
{
[[self nextResponder] keyDown:event];
}
else
{
[super keyDown:event];
}
}

#if 0
#pragma mark -
#pragma mark Resize box
#endif

- (NSRect) growBoxRect
{
NSRect bounds = [self bounds];
NSRect growBoxRect;

growBoxRect.size.width = 16;
growBoxRect.size.height = 16;
growBoxRect.origin.y = NSMaxY(bounds) - growBoxRect.size.height;
growBoxRect.origin.x = NSMaxX(bounds) - growBoxRect.size.width;

return growBoxRect;
}

- (void) drawRect:(NSRect)rect
{
// NSRect bounds = [self bounds];
NSRect growBoxRect = [self growBoxRect];

[super drawRect:rect];

if( NSContainsRect(rect, growBoxRect) )
{
[NSGraphicsContext saveGraphicsState];
[[NSColor darkGrayColor] set];

[NSBezierPath clipRect:NSInsetRect(growBoxRect, 1, 1)];

[NSBezierPath strokeLineFromPoint:NSMakePoint(growBoxRect.origin.x, growBoxRect.origin.y + 20 )
toPoint:NSMakePoint(growBoxRect.origin.x + 20, growBoxRect.origin.y)];
[NSBezierPath strokeLineFromPoint:NSMakePoint(growBoxRect.origin.x, growBoxRect.origin.y + 24)
toPoint:NSMakePoint(growBoxRect.origin.x + 24, growBoxRect.origin.y)];
[NSBezierPath strokeLineFromPoint:NSMakePoint(growBoxRect.origin.x, growBoxRect.origin.y + 28)
toPoint:NSMakePoint(growBoxRect.origin.x + 28, growBoxRect.origin.y)];
[NSGraphicsContext restoreGraphicsState];
}

}

- (void) mouseDown:(NSEvent *)event
{
NSPoint locationInWindow = [event locationInWindow];
NSPoint locationInView = [self convertPoint:locationInWindow fromView:nil];
NSRect growBoxRect = [self growBoxRect];

if( NSMouseInRect(locationInView, growBoxRect, YES) )
{
fInitialViewFrame = [[self enclosingScrollView] frame];
fInitialMousePoint = locationInWindow;
fTrackingGrowBox = YES;
}
else
{
[super mouseDown:event];
}
}

- (void) mouseUp:(NSEvent *)event
{
if(fTrackingGrowBox)
{
fTrackingGrowBox = NO;
}
else
{
[super mouseUp:event];
}
}

- (void) mouseDragged:(NSEvent *)event
{
NSPoint currentPoint = [event locationInWindow];//[self convertPoint: fromView:nil];

if(fTrackingGrowBox)
{
NSScrollView * scrollView = [self enclosingScrollView];
NSRect scrollFrame = [scrollView frame];
NSRect newFrame = scrollFrame;
float deltaY;

// Horizontal
if( fAllowGrowHorizontally )
{
newFrame.size.width = fInitialViewFrame.size.width + (currentPoint.x - fInitialMousePoint.x);
if(newFrame.size.width < fMinWidth )
{
newFrame.size.width = fMinWidth;
}
else if(newFrame.size.width > fMaxWidth )
{
newFrame.size.width = fMaxWidth;
}
}

// Vertical (FIXME: assumes the scroll view's superview is _not_ flipped)
if( fAllowGrowVertically )
{
deltaY = currentPoint.y - fInitialMousePoint.y;
newFrame.size.height = fInitialViewFrame.size.height - deltaY;

// Check size
if(newFrame.size.height < fMinHeight )
{
newFrame.size.height = fMinHeight;
}
else if(newFrame.size.height > fMaxHeight )
{
newFrame.size.height = fMaxHeight;
}

// Adjust origin of frame
newFrame.origin.y += scrollFrame.size.height - newFrame.size.height;
}

[scrollView setNeedsDisplayInRect:[scrollView bounds]];
[scrollView setFrame:newFrame];
[[NSCursor arrowCursor] set];
}
else
{
[super mouseDragged:event];
}
}

// This alone is not enough -- see mouseMoved: below -- but it does cause the arrow to be correctly displayed during resize
- (void) resetCursorRects
{
[super resetCursorRects];
[self addCursorRect:[self growBoxRect] cursor:[NSCursor arrowCursor]];
}

// Required to override NSTextView's setting of the cursor during mouseMoved events
- (void) mouseMoved:(NSEvent *)event
{
NSPoint locationInWindow = [event locationInWindow];
NSPoint locationInView = [self convertPoint:locationInWindow fromView:nil];
NSRect growBoxRect = [self growBoxRect];

if( NSMouseInRect(locationInView, growBoxRect, YES) )
{
[[NSCursor arrowCursor] set];
}
else
{
[super mouseMoved:event];
}
}

#if 0
#pragma mark -
#pragma mark Simple accessors
#endif

// Grow planes

- (BOOL)allowHorizontalResize
{
return fAllowGrowHorizontally;
}

- (void)setAllowHorizontalResize:(BOOL)newAllowGrowHorizontally
{
fAllowGrowHorizontally = newAllowGrowHorizontally;
}

- (BOOL)allowVerticalResize
{
return fAllowGrowVertically;
}

- (void)setAllowVerticalResize:(BOOL)newAllowGrowVertically
{
fAllowGrowVertically = newAllowGrowVertically;
}

// Geometry

- (float)maxWidth
{
return fMaxWidth;
}

- (void)setMaxWidth:(float)newMaxWidth
{
fMaxWidth = newMaxWidth;
}

- (float)minWidth
{
return fMinWidth;
}

- (void)setMinWidth:(float)newMinWidth
{
fMinWidth = newMinWidth;
}

- (float)minHeight
{
return fMinHeight;
}

- (void)setMinHeight:(float)newMinHeight
{
fMinHeight = newMinHeight;
}

- (float)maxHeight
{
return fMaxHeight;
}

- (void)setMaxHeight:(float)newMaxHeight
{
fMaxHeight = newMaxHeight;
}


@end
18 changes: 18 additions & 0 deletions CommitWindow/CXMenuButton.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// CXMenuButton.h
//
// Created by Chris Thomas on 2006-10-09.
// Copyright 2006 Chris Thomas. All rights reserved.
// MIT license.
//

@interface CXMenuButton : NSButton
{
IBOutlet NSMenu * menu;
}

- (NSMenu *)menu;
- (void)setMenu:(NSMenu *)aValue;


@end
53 changes: 53 additions & 0 deletions CommitWindow/CXMenuButton.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// CXMenuButton.m
//
// Created by Chris Thomas on 2006-10-09.
// Copyright 2006 Chris Thomas. All rights reserved.
// MIT license.
//

#import "CXMenuButton.h"

@implementation CXMenuButton

// Initialization

- (void) commonInit
{
// Use alternateImage for pressed state
[[self cell] setHighlightsBy:NSCellLightsByContents];
}

- (void) awakeFromNib
{
[self commonInit];
}

// Events

- (void) mouseDown:(NSEvent *)event
{
[self highlight:YES];
[NSMenu popUpContextMenu:menu withEvent:event forView:self withFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
[self highlight:NO];
}

// Accessors

- (NSMenu *)menu
{
return menu;
}

- (void)setMenu:(NSMenu *)aValue
{
NSMenu *oldMenu = menu;
menu = [aValue retain];
[oldMenu release];
}

@end




Loading

0 comments on commit 3dcd5a3

Please sign in to comment.