darling-cocotron/AppKit/NSComboBoxWindow.m

93 lines
3.0 KiB
Mathematica
Raw Normal View History

/* Copyright (c) 2006-2007 Christopher J. W. Lloyd
2006-12-22 04:41:44 +00:00
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
2006-12-22 04:41:44 +00:00
// Original - Christopher Lloyd <cjwl@objc.net>
#import <AppKit/NSComboBoxView.h>
#import <AppKit/NSComboBoxWindow.h>
2006-12-22 04:41:44 +00:00
@implementation NSComboBoxWindow
- initWithFrame: (NSRect) frame {
NSRect rect = NSZeroRect;
2006-12-22 04:41:44 +00:00
[self initWithContentRect: frame
styleMask: NSBorderlessWindowMask
backing: NSBackingStoreBuffered
defer: NO];
[self setLevel: NSPopUpMenuWindowLevel];
_releaseWhenClosed = YES;
2006-12-22 04:41:44 +00:00
rect.size = frame.size;
_scrollView = [[NSScrollView alloc] initWithFrame: rect];
[_scrollView setHasVerticalScroller: NO];
[_scrollView setHasHorizontalScroller: NO];
[_scrollView setBorderType: NSLineBorder];
2006-12-22 04:41:44 +00:00
[[self contentView] addSubview: _scrollView];
2006-12-22 04:41:44 +00:00
rect.size = [_scrollView contentSize];
_view = [[NSComboBoxView alloc] initWithFrame: rect];
[_scrollView setDocumentView: _view];
2006-12-22 04:41:44 +00:00
return self;
2006-12-22 04:41:44 +00:00
}
- (void) dealloc {
[_view release];
[_scrollView release];
[super dealloc];
2006-12-22 04:41:44 +00:00
}
- (void) setObjectArray: (NSArray *) objects {
[_view setObjectArray: objects];
2006-12-22 04:41:44 +00:00
}
- (void) setFont: (NSFont *) font {
[_view setFont: font];
2006-12-22 04:41:44 +00:00
}
- (void) setSelectedIndex: (int) index {
[_view setSelectedIndex: index];
}
- (int) runTrackingWithEvent: (NSEvent *) event {
NSSize size = [_view sizeForContents];
NSSize scrollViewSize = [NSScrollView
2020-05-12 18:51:39 +00:00
frameSizeForContentSize: size
hasHorizontalScroller: [_scrollView hasHorizontalScroller]
hasVerticalScroller: [_scrollView hasVerticalScroller]
borderType: NSLineBorder];
NSRect frame;
2006-12-22 04:41:44 +00:00
frame = [self frame];
frame.size = scrollViewSize;
frame.origin.y -= size.height;
[self setFrame: frame display: YES];
2006-12-22 04:41:44 +00:00
[_scrollView setFrameSize: scrollViewSize];
[_scrollView setFrameOrigin: NSMakePoint(0, 0)];
2006-12-22 04:41:44 +00:00
[_view setFrameSize: size];
[_view setFrameOrigin: NSMakePoint(0, 0)];
2006-12-22 04:41:44 +00:00
return [_view runTrackingWithEvent: event];
2006-12-22 04:41:44 +00:00
}
@end