Fix problems with 'fullscreen' and :mksession
[MacVim.git] / src / MacVim / MMWindow.m
blob51a03ad4ed5d9407e305cc44af48a84a471ee255
1 /* vi:set ts=8 sts=4 sw=4 ft=objc:
2  *
3  * VIM - Vi IMproved            by Bram Moolenaar
4  *                              MacVim GUI port by Bjorn Winckler
5  *
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.
9  */
11  * MMWindow
12  *
13  * A normal window with a (possibly hidden) tabline separator at the top of the
14  * content view.
15  *
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
18  * is visible or not.
19  *
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
26  * 'size'.
27  */
29 #import "MMWindow.h"
30 #import "Miscellaneous.h"
35 @implementation MMWindow
37 - (id)initWithContentRect:(NSRect)rect
38                 styleMask:(unsigned int)style
39                   backing:(NSBackingStoreType)bufferingType
40                     defer:(BOOL)flag
42     self = [super initWithContentRect:rect
43                             styleMask:style
44                               backing:bufferingType
45                                 defer:flag];
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];
52     
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];
61     return self;
64 - (void)dealloc
66     LOG_DEALLOC
68     // TODO: Is there any reason why we would want the following call?
69     //[tablineSeparator removeFromSuperviewWithoutNeedingDisplay];
70     [tablineSeparator release];  tablineSeparator = nil;
71     [super dealloc];
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])
87         --rect.size.height;
89     return rect;
92 - (NSRect)frameRectForContentRect:(NSRect)rect
94     NSRect frame = [super frameRectForContentRect:rect];
95     if (![tablineSeparator isHidden])
96         ++frame.size.height;
98     return frame;
101 - (void)setContentMinSize:(NSSize)size
103     if (![tablineSeparator isHidden])
104         ++size.height;
106     [super setContentMinSize:size];
109 - (void)setContentMaxSize:(NSSize)size
111     if (![tablineSeparator isHidden])
112         ++size.height;
114     [super setContentMaxSize:size];
117 - (void)setContentSize:(NSSize)size
119     if (![tablineSeparator isHidden])
120         ++size.height;
122     [super setContentSize:size];
125 - (void)performClose:(id)sender
127     id wc = [self windowController];
128     if ([wc respondsToSelector:@selector(performClose:)])
129         [wc performClose:sender];
130     else
131         [super performClose:sender];
134 - (BOOL)validateMenuItem:(NSMenuItem *)item
136     if ([item action] == @selector(vimMenuItemAction:)
137             || [item action] == @selector(performClose:))
138         return [item tag];
140     return YES;
143 @end // MMWindow