Line numbers are brighter when bg=dark
[MacVim.git] / src / MacVim / MMWindow.m
blobdae9087a56dfd0fd3f792073d18fdfca9c5ee6f7
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     [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     // TODO: Is there any reason why we would want the following call?
67     //[tablineSeparator removeFromSuperviewWithoutNeedingDisplay];
68     [tablineSeparator release];  tablineSeparator = nil;
69     [super dealloc];
72 - (BOOL)hideTablineSeparator:(BOOL)hide
74     BOOL isHidden = [tablineSeparator isHidden];
75     [tablineSeparator setHidden:hide];
77     // Return YES if visibility state was toggled, NO if it was unchanged.
78     return isHidden != hide;
81 - (NSRect)contentRectForFrameRect:(NSRect)frame
83     NSRect rect = [super contentRectForFrameRect:frame];
84     if (![tablineSeparator isHidden])
85         --rect.size.height;
87     return rect;
90 - (NSRect)frameRectForContentRect:(NSRect)rect
92     NSRect frame = [super frameRectForContentRect:rect];
93     if (![tablineSeparator isHidden])
94         ++frame.size.height;
96     return frame;
99 - (void)setContentMinSize:(NSSize)size
101     if (![tablineSeparator isHidden])
102         ++size.height;
104     [super setContentMinSize:size];
107 - (void)setContentMaxSize:(NSSize)size
109     if (![tablineSeparator isHidden])
110         ++size.height;
112     [super setContentMaxSize:size];
115 - (void)setContentSize:(NSSize)size
117     if (![tablineSeparator isHidden])
118         ++size.height;
120     [super setContentSize:size];
123 - (void)performClose:(id)sender
125     id wc = [self windowController];
126     if ([wc respondsToSelector:@selector(performClose:)])
127         [wc performClose:sender];
128     else
129         [super performClose:sender];
132 @end // MMWindow