1 /* vi:set ts=8 sts=4 sw=4 ft=objc:
3 * VIM - Vi IMproved by Bram Moolenaar
4 * MacVim GUI port by Bjorn Winckler
6 * Do ":help uganda" in Vim to read copying and usage conditions.
7 * Do ":help credits" in Vim to see a list of people who contributed.
8 * See README.txt for an overview of the Vim source code.
13 * A normal window with a (possibly hidden) tabline separator at the top of the
16 * The main point of this class is for the window controller to be able to call
17 * contentRectForFrameRect: without having to worry about whether the separator
20 * This is a bit of a hack, it would be nicer to be able to leave the content
21 * view alone, but as it is the tabline separator is a subview of the content
22 * view. Since we want to pretend that the content view does not contain the
23 * separator this leads to some dangerous situations. For instance, calling
24 * [window setContentMinSize:size] when the separator is visible results in
25 * size != [window contentMinSize], since the latter is one pixel higher than
30 #import "Miscellaneous.h"
35 @implementation MMWindow
37 - (id)initWithContentRect:(NSRect)rect
38 styleMask:(unsigned int)style
39 backing:(NSBackingStoreType)bufferingType
42 self = [super initWithContentRect:rect
46 if (!self) return nil;
48 [self setReleasedWhenClosed:NO];
50 NSRect tabSepRect = { 0, rect.size.height - 1, rect.size.width, 1 };
51 tablineSeparator = [[NSBox alloc] initWithFrame:tabSepRect];
53 [tablineSeparator setBoxType:NSBoxSeparator];
54 [tablineSeparator setHidden:YES];
55 [tablineSeparator setAutoresizingMask:NSViewWidthSizable|NSViewMinYMargin];
57 NSView *contentView = [self contentView];
58 [contentView setAutoresizesSubviews:YES];
59 [contentView addSubview:tablineSeparator];
68 // TODO: Is there any reason why we would want the following call?
69 //[tablineSeparator removeFromSuperviewWithoutNeedingDisplay];
70 [tablineSeparator release]; tablineSeparator = nil;
74 - (BOOL)hideTablineSeparator:(BOOL)hide
76 BOOL isHidden = [tablineSeparator isHidden];
77 [tablineSeparator setHidden:hide];
79 // Return YES if visibility state was toggled, NO if it was unchanged.
80 return isHidden != hide;
83 - (NSRect)contentRectForFrameRect:(NSRect)frame
85 NSRect rect = [super contentRectForFrameRect:frame];
86 if (![tablineSeparator isHidden])
92 - (NSRect)frameRectForContentRect:(NSRect)rect
94 NSRect frame = [super frameRectForContentRect:rect];
95 if (![tablineSeparator isHidden])
101 - (void)setContentMinSize:(NSSize)size
103 if (![tablineSeparator isHidden])
106 [super setContentMinSize:size];
109 - (void)setContentMaxSize:(NSSize)size
111 if (![tablineSeparator isHidden])
114 [super setContentMaxSize:size];
117 - (void)setContentSize:(NSSize)size
119 if (![tablineSeparator isHidden])
122 [super setContentSize:size];
125 - (void)performClose:(id)sender
127 id wc = [self windowController];
128 if ([wc respondsToSelector:@selector(performClose:)])
129 [wc performClose:sender];
131 [super performClose:sender];
134 - (BOOL)validateMenuItem:(NSMenuItem *)item
136 if ([item action] == @selector(vimMenuItemAction:)
137 || [item action] == @selector(performClose:))
143 - (IBAction)zoom:(id)sender
145 NSScreen *screen = [self screen];
147 ASLogNotice(@"Window not on screen, zoom to main screen");
148 screen = [NSScreen mainScreen];
150 ASLogNotice(@"No main screen, abort zoom");
155 NSRect frame = [self frame];
156 NSRect defaultFrame = [screen visibleFrame];
157 defaultFrame = [[self delegate] windowWillUseStandardFrame:self
158 defaultFrame:defaultFrame];
160 // TODO: Check if width & height differs by cellSize or more.
161 BOOL isZoomed = ((abs(frame.size.width - defaultFrame.size.width) < 8) &&
162 (abs(frame.size.height - defaultFrame.size.height) < 8));
165 if (userFrame.size.width > 0 && userFrame.size.height > 0)
166 defaultFrame = userFrame;
171 [self setFrame:defaultFrame display:YES];