Dialogs are always displayed in the default run loop mode
[MacVim.git] / src / MacVim / MMWindow.m
blob139db4cfc1323893cfcc9998df2c6eba23ae4336
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"
34 @implementation MMWindow
36 - (id)initWithContentRect:(NSRect)rect
37                 styleMask:(unsigned int)style
38                   backing:(NSBackingStoreType)bufferingType
39                     defer:(BOOL)flag
41     self = [super initWithContentRect:rect
42                             styleMask:style
43                               backing:bufferingType
44                                 defer:flag];
45     if (!self) return nil;
47     [self setReleasedWhenClosed:NO];
49     NSRect tabSepRect = { 0, rect.size.height - 1, rect.size.width, 1 };
50     tablineSeparator = [[NSBox alloc] initWithFrame:tabSepRect];
51     
52     [tablineSeparator setBoxType:NSBoxSeparator];
53     [tablineSeparator setHidden:YES];
54     [tablineSeparator setAutoresizingMask:NSViewWidthSizable|NSViewMinYMargin];
56     NSView *contentView = [self contentView];
57     [contentView setAutoresizesSubviews:YES];
58     [contentView addSubview:tablineSeparator];
60     return self;
63 - (void)dealloc
65     // TODO: Is there any reason why we would want the following call?
66     //[tablineSeparator removeFromSuperviewWithoutNeedingDisplay];
67     [tablineSeparator release];  tablineSeparator = nil;
68     [super dealloc];
71 - (BOOL)hideTablineSeparator:(BOOL)hide
73     BOOL isHidden = [tablineSeparator isHidden];
74     [tablineSeparator setHidden:hide];
76     // Return YES if visibility state was toggled, NO if it was unchanged.
77     return isHidden != hide;
80 - (NSRect)contentRectForFrameRect:(NSRect)frame
82     NSRect rect = [super contentRectForFrameRect:frame];
83     if (![tablineSeparator isHidden])
84         --rect.size.height;
86     return rect;
89 - (NSRect)frameRectForContentRect:(NSRect)rect
91     NSRect frame = [super frameRectForContentRect:rect];
92     if (![tablineSeparator isHidden])
93         ++frame.size.height;
95     return frame;
98 - (void)setContentMinSize:(NSSize)size
100     if (![tablineSeparator isHidden])
101         ++size.height;
103     [super setContentMinSize:size];
106 - (void)setContentMaxSize:(NSSize)size
108     if (![tablineSeparator isHidden])
109         ++size.height;
111     [super setContentMaxSize:size];
114 - (void)setContentSize:(NSSize)size
116     if (![tablineSeparator isHidden])
117         ++size.height;
119     [super setContentSize:size];
122 - (void)performClose:(id)sender
124     id wc = [self windowController];
125     if ([wc respondsToSelector:@selector(performClose:)])
126         [wc performClose:sender];
127     else
128         [super performClose:sender];
131 - (BOOL)validateMenuItem:(NSMenuItem *)item
133     if ([item action] == @selector(vimMenuItemAction:)
134             || [item action] == @selector(performClose:))
135         return [item tag];
137     return YES;
140 @end // MMWindow