- Text view now drawn with inset - Added user defaults to control text view inset -inset[left|right|top|bottom]

git-svn-id: http://macvim.googlecode.com/svn/trunk@61 96c4425d-ca35-0410-94e5-3396d5c13a8f
This commit is contained in:
Bjorn Winckler
2007-08-02 06:19:18 +00:00
parent 18737386cd
commit 2fb4387bdc
3 changed files with 51 additions and 10 deletions
+4
View File
@@ -18,6 +18,10 @@ extern NSString *MMTabMinWidthKey;
extern NSString *MMTabMaxWidthKey;
extern NSString *MMTabOptimumWidthKey;
extern NSString *MMStatuslineOffKey;
extern NSString *MMTextInsetLeft;
extern NSString *MMTextInsetRight;
extern NSString *MMTextInsetTop;
extern NSString *MMTextInsetBottom;
+8
View File
@@ -19,6 +19,10 @@ NSString *MMTabMinWidthKey = @"tabminwidth";
NSString *MMTabMaxWidthKey = @"tabmaxwidth";
NSString *MMTabOptimumWidthKey = @"taboptimumwidth";
NSString *MMStatuslineOffKey = @"statuslineoff";
NSString *MMTextInsetLeft = @"insetleft";
NSString *MMTextInsetRight = @"insetright";
NSString *MMTextInsetTop = @"insettop";
NSString *MMTextInsetBottom = @"insetbottom";
@@ -32,6 +36,10 @@ NSString *MMStatuslineOffKey = @"statuslineoff";
[NSNumber numberWithInt:6*64], MMTabMaxWidthKey,
[NSNumber numberWithInt:132], MMTabOptimumWidthKey,
[NSNumber numberWithBool:NO], MMStatuslineOffKey,
[NSNumber numberWithInt:2], MMTextInsetLeft,
[NSNumber numberWithInt:1], MMTextInsetRight,
[NSNumber numberWithInt:1], MMTextInsetTop,
[NSNumber numberWithInt:1], MMTextInsetBottom,
nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:dict];
+39 -10
View File
@@ -49,8 +49,9 @@ static float StatusLineHeight = 16.0f;
@end
@interface MMWindowController (Private)
- (NSSize)contentSizeForTextViewSize:(NSSize)textViewSize;
- (NSSize)contentSizeForTextStorageSize:(NSSize)textViewSize;
- (NSRect)textViewRectForContentSize:(NSSize)contentSize;
- (NSSize)textStorageSizeForTextViewSize:(NSSize)textViewSize;
- (void)resizeWindowToFit:(id)sender;
- (NSRect)fitWindowToFrame:(NSRect)frame;
- (void)updateResizeIncrements;
@@ -145,6 +146,11 @@ NSMutableArray *buildMenuAddress(NSMenu *menu)
textView = [[MMTextView alloc] initWithFrame:NSZeroRect
textContainer:tc];
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
int left = [ud integerForKey:MMTextInsetLeft];
int top = [ud integerForKey:MMTextInsetTop];
[textView setTextContainerInset:NSMakeSize(left, top)];
// The text storage retains the layout manager which in turn retains the
// text container.
[tc release];
@@ -587,10 +593,17 @@ NSMutableArray *buildMenuAddress(NSMenu *menu)
@implementation MMWindowController (Private)
- (NSSize)contentSizeForTextViewSize:(NSSize)textViewSize
- (NSSize)contentSizeForTextStorageSize:(NSSize)textViewSize
{
NSSize size = textViewSize;
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
int right = [ud integerForKey:MMTextInsetRight];
int bot = [ud integerForKey:MMTextInsetBottom];
size.width += [textView textContainerOrigin].x + right;
size.height += [textView textContainerOrigin].y + bot;
if (![tabBarControl isHidden])
size.height += [tabBarControl frame].size.height;
if (![[NSUserDefaults standardUserDefaults] boolForKey:MMStatuslineOffKey])
@@ -632,6 +645,20 @@ NSMutableArray *buildMenuAddress(NSMenu *menu)
return rect;
}
- (NSSize)textStorageSizeForTextViewSize:(NSSize)textViewSize
{
NSSize size = textViewSize;
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
int right = [ud integerForKey:MMTextInsetRight];
int bot = [ud integerForKey:MMTextInsetBottom];
size.width -= [textView textContainerOrigin].x + right;
size.height -= [textView textContainerOrigin].y + bot;
return size;
}
- (void)resizeWindowToFit:(id)sender
{
if (!setupDone) return;
@@ -639,7 +666,7 @@ NSMutableArray *buildMenuAddress(NSMenu *menu)
NSWindow *win = [self window];
NSRect frame = [win frame];
NSRect contentRect = [win contentRectForFrameRect:frame];
NSSize newSize = [self contentSizeForTextViewSize:[textStorage size]];
NSSize newSize = [self contentSizeForTextStorageSize:[textStorage size]];
// Keep top-left corner of the window fixed when resizing.
contentRect.origin.y -= newSize.height - contentRect.size.height;
@@ -681,13 +708,14 @@ NSMutableArray *buildMenuAddress(NSMenu *menu)
NSWindow *win = [self window];
NSRect contentRect = [win contentRectForFrameRect:frame];
NSRect textViewRect = [self textViewRectForContentSize:contentRect.size];
NSSize fitSize = [textStorage fitToSize:textViewRect.size];
NSSize newSize = [self contentSizeForTextViewSize:fitSize];
NSSize size = [self textViewRectForContentSize:contentRect.size].size;
size = [self textStorageSizeForTextViewSize:size];
size = [textStorage fitToSize:size];
size = [self contentSizeForTextStorageSize:size];
// Keep top-left corner of 'frame' fixed.
contentRect.origin.y -= newSize.height - contentRect.size.height;
contentRect.size = newSize;
contentRect.origin.y -= size.height - contentRect.size.height;
contentRect.size = size;
return [win frameRectForContentRect:contentRect];
}
@@ -933,15 +961,16 @@ NSMutableArray *buildMenuAddress(NSMenu *menu)
NSWindow *win = [self window];
NSRect contentRect = [win contentRectForFrameRect:[win frame]];
NSRect textViewRect = [self textViewRectForContentSize:contentRect.size];
NSSize tsSize = [self textStorageSizeForTextViewSize:textViewRect.size];
#if 0
if ([textStorage resizeToFitSize:textViewRect.size]) {
if ([textStorage resizeToFitSize:tsSize]) {
// Text storage dimensions changed, notify the VimTask.
int dim[2];
[textStorage getMaxRows:&dim[0] columns:&dim[1]];
#else
int dim[2], rows, cols;
[textStorage getMaxRows:&rows columns:&cols];
[textStorage fitToSize:textViewRect.size rows:&dim[0] columns:&dim[1]];
[textStorage fitToSize:tsSize rows:&dim[0] columns:&dim[1]];
if (dim[0] != rows || dim[1] != cols) {
#endif
NSString *sdim = [NSString stringWithFormat:@"%dx%d", dim[1], dim[0]];