/* NSComboBoxCell.m Copyright (C) 1999 Free Software Foundation, Inc. Author: Gerrit van Dyk Date: 1999 This file is part of the GNUstep GUI Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #import #import "GSComboSupport.h" @interface NSComboBoxCell(_Private_) - (void)_createButtonCell; - (void)_didClick:(id)sender; - (NSImage *)_buttonImage; - (GSComboWindow *)_popUp; @end @implementation NSComboBoxCell - (id)initTextCell:(NSString *)aString { self = [super initTextCell:aString]; _delegate = nil; _dataSource = nil; _buttonCell = nil; _popUpList = [[NSMutableArray array] retain]; _usesDataSource = NO; _visibleItems = 10; _intercellSpacing = NSMakeSize(0.0,0.0); _itemHeight = 14; _popView = nil; _canPop = NO; _popRect = NSZeroRect; _mUpEvent = nil; [self _createButtonCell]; return self; } - (void)dealloc { [_delegate release]; [_dataSource release]; [_buttonCell release]; [_popUpList release]; [super dealloc]; } - (BOOL)hasVerticalScroller { return _hasVerticalScroller; } - (void)setHasVerticalScroller:(BOOL)flag { _hasVerticalScroller = flag; } - (NSSize)intercellSpacing { return _intercellSpacing; } - (void)setIntercellSpacing:(NSSize)aSize { _intercellSpacing = aSize; } - (float)itemHeight { return _itemHeight; } - (void)setItemHeight:(float)itemHeight { if (itemHeight > 14) _itemHeight = itemHeight; } - (int)numberOfVisibleItems { return _visibleItems; } - (void)setNumberOfVisibleItems:(int)visibleItems { if (_visibleItems > 10) _visibleItems = visibleItems; } - (void)reloadData { } - (void)noteNumberOfItemsChanged { } - (BOOL)usesDataSource { return _usesDataSource; } - (void)setUsesDataSource:(BOOL)flag { _usesDataSource = flag; } - (void)scrollItemAtIndexToTop:(int)index { } - (void)scrollItemAtIndexToVisible:(int)index { } - (void)selectItemAtIndex:(int)index { } - (void)deselectItemAtIndex:(int)index { } - (int)indexOfSelectedItem { return 0; } - (int)numberOfItems { SEL selector; if (_usesDataSource) { if (!_dataSource) NSLog(@"No DataSource Specified"); else { if ([[self controlView] isKindOfClass:[NSComboBox class]]) { selector = @selector(numberOfItemsInComboBox:); if ([_dataSource respondsToSelector:selector]) return [_dataSource numberOfItemsInComboBox: (NSComboBox *)[self controlView]]; } else { selector = @selector(numberOfItemsInComboBoxCell:); if ([_dataSource respondsToSelector:selector]) return [_dataSource numberOfItemsInComboBoxCell:self]; } } } else return [_popUpList count]; return 0; } - (id)dataSource { return _dataSource; } - (void)setDataSource:(id)aSource { if (_dataSource != aSource) { [_dataSource release]; _dataSource = [aSource retain]; } } - (void)addItemWithObjectValue:(id)object { if (_usesDataSource) NSLog(@"Method Invalid: ComboBox uses dataSource"); else [_popUpList addObject:object]; } - (void)addItemsWithObjectValues:(NSArray *)objects { if (_usesDataSource) NSLog(@"Method Invalid: ComboBox uses dataSource"); else [_popUpList addObjectsFromArray:objects]; } - (void)insertItemWithObjectValue:(id)object atIndex:(int)index { if (_usesDataSource) NSLog(@"Method Invalid: ComboBox uses dataSource"); else [_popUpList insertObject:object atIndex:index]; } - (void)removeItemWithObjectValue:(id)object { if (_usesDataSource) NSLog(@"Method Invalid: ComboBox uses dataSource"); else [_popUpList removeObject:object]; } - (void)removeItemAtIndex:(int)index { if (_usesDataSource) NSLog(@"Method Invalid: ComboBox uses dataSource"); else [_popUpList removeObjectAtIndex:index]; } - (void)removeAllItems { if (_usesDataSource) NSLog(@"Method Invalid: ComboBox uses dataSource"); else [_popUpList removeAllObjects]; } - (void)selectItemWithObjectValue:(id)object { if (_usesDataSource) NSLog(@"Method Invalid: ComboBox uses dataSource"); } - (id)itemObjectValueAtIndex:(int)index { if (_usesDataSource) NSLog(@"Method Invalid: ComboBox uses dataSource"); return nil; } - (id)objectValueOfSelectedItem { if (_usesDataSource) NSLog(@"Method Invalid: ComboBox uses dataSource"); return nil; } - (int)indexOfItemWithObjectValue:(id)object { if (_usesDataSource) { NSLog(@"Method Invalid: ComboBox uses dataSource"); return 0; } return [_popUpList indexOfObject:object]; } - (NSArray *)_dataSourceObjectValues { NSMutableArray *array = nil; id obj; SEL selector; int i,cnt; if (!_dataSource) NSLog(@"No DataSource Specified"); else { cnt = [self numberOfItems]; if ([[self controlView] isKindOfClass:[NSComboBox class]]) { obj = [self controlView]; selector = @selector(comboBox:objectValueForItemAtIndex:); if ([_dataSource respondsToSelector:selector]) { array = [NSMutableArray array]; for (i=0;i= 0) goto popUp; oldPoint = point; point = _popRect.origin; if (![_popView isFlipped]) point.y += NSHeight(_popRect); point = [[_popView window] convertBaseToScreen:point]; if (point.y > NSHeight([[[_popView window] screen] frame])) point = oldPoint; if (point.y+size.height > NSHeight([[[_popView window] screen] frame])) point.y = NSHeight([[[_popView window] screen] frame]) - size.height; popUp: if (point.x+size.width > NSWidth([[[_popView window] screen] frame])) point.x = NSWidth([[[_popView window] screen] frame]) - size.width; if (point.x < 0.0) point.x = 0.0; [[self _popUp] popUpCell:self popUpAt:point width:NSWidth(_popRect)]; } - (NSImage *)_buttonImage { return [NSImage imageNamed: @"NSComboArrow"]; } - (NSEvent *)_mouseUpEvent { return _mUpEvent; _mUpEvent = nil; } - (GSComboWindow *)_popUp { return [GSComboWindow defaultPopUp]; } @end