File->Close sends performClose:
[MacVim.git] / src / MacVim / MMWindow.m
blob70a9fd2ef7995a6be5175019171c353efed90269
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 "MacVim.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     NSRect tabSepRect = { 0, rect.size.height - 1, rect.size.width, 1 };
49     tablineSeparator = [[NSBox alloc] initWithFrame:tabSepRect];
50     
51     [tablineSeparator setBoxType:NSBoxSeparator];
52     [tablineSeparator setHidden:YES];
53     [tablineSeparator setAutoresizingMask:NSViewWidthSizable|NSViewMinYMargin];
55     NSView *contentView = [self contentView];
56     [contentView setAutoresizesSubviews:YES];
57     [contentView addSubview:tablineSeparator];
59     return self;
62 - (void)dealloc
64     [tablineSeparator removeFromSuperviewWithoutNeedingDisplay];
65     [tablineSeparator release];  tablineSeparator = nil;
66     [super dealloc];
69 - (BOOL)hideTablineSeparator:(BOOL)hide
71     BOOL isHidden = [tablineSeparator isHidden];
72     [tablineSeparator setHidden:hide];
74     // Return YES if visibility state was toggled, NO if it was unchanged.
75     return isHidden != hide;
78 - (NSRect)contentRectForFrameRect:(NSRect)frame
80     NSRect rect = [super contentRectForFrameRect:frame];
81     if (![tablineSeparator isHidden])
82         --rect.size.height;
84     return rect;
87 - (NSRect)frameRectForContentRect:(NSRect)rect
89     NSRect frame = [super frameRectForContentRect:rect];
90     if (![tablineSeparator isHidden])
91         ++frame.size.height;
93     return frame;
96 - (void)setContentMinSize:(NSSize)size
98     if (![tablineSeparator isHidden])
99         ++size.height;
101     [super setContentMinSize:size];
104 - (void)setContentMaxSize:(NSSize)size
106     if (![tablineSeparator isHidden])
107         ++size.height;
109     [super setContentMaxSize:size];
112 - (void)setContentSize:(NSSize)size
114     if (![tablineSeparator isHidden])
115         ++size.height;
117     [super setContentSize:size];
120 - (void)performClose:(id)sender
122     id wc = [self windowController];
123     if ([wc respondsToSelector:@selector(performClose:)])
124         [wc performClose:sender];
125     else
126         [super performClose:sender];
129 @end // MMWindow