libs-gui/Source/NSComboBox.m
qmathe 6a2a5d22e2 Rewritten combo box implementation
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@19418 72102866-910b-0410-8b05-ffd578937521
2004-05-29 13:17:21 +00:00

262 lines
5.1 KiB
Objective-C

/** <title>NSComboBox</title>
Copyright (C) 1999 Free Software Foundation, Inc.
Author: Gerrit van Dyk <gerritvd@decillion.net>
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.
*/
#include <Foundation/NSNotification.h>
#include <Foundation/NSString.h>
#include "AppKit/NSComboBox.h"
#include "AppKit/NSComboBoxCell.h"
#include "AppKit/NSEvent.h"
/*
* Class variables
*/
static Class usedCellClass;
static Class comboBoxCellClass;
static NSNotificationCenter *nc;
@implementation NSComboBox
+ (void) initialize
{
if (self == [NSComboBox class]) // Is such test case really needed ?
{
[self setVersion: 1];
comboBoxCellClass = [NSComboBoxCell class];
usedCellClass = comboBoxCellClass;
nc = [NSNotificationCenter defaultCenter];
}
}
/*
* Setting the Cell class
*/
+ (Class) cellClass
{
return usedCellClass;
}
+ (void) setCellClass: (Class)factoryId
{
usedCellClass = factoryId ? factoryId : comboBoxCellClass;
}
- (BOOL)hasVerticalScroller
{
return [_cell hasVerticalScroller];
}
- (void)setHasVerticalScroller:(BOOL)flag
{
[_cell setHasVerticalScroller:flag];
}
- (NSSize)intercellSpacing
{
return [_cell intercellSpacing];
}
- (void)setIntercellSpacing:(NSSize)aSize
{
[_cell setIntercellSpacing:aSize];
}
- (float)itemHeight
{
return [_cell itemHeight];
}
- (void)setItemHeight:(float)itemHeight
{
[_cell setItemHeight:itemHeight];
}
- (int)numberOfVisibleItems
{
return [_cell numberOfVisibleItems];
}
- (void)setNumberOfVisibleItems:(int)visibleItems
{
[_cell setNumberOfVisibleItems:visibleItems];
}
- (void)reloadData
{
[_cell reloadData];
}
- (void)noteNumberOfItemsChanged
{
[_cell noteNumberOfItemsChanged];
}
- (BOOL)usesDataSource
{
return [_cell usesDataSource];
}
- (void)setUsesDataSource:(BOOL)flag
{
[_cell setUsesDataSource:flag];
}
- (void)scrollItemAtIndexToTop:(int)index
{
[_cell scrollItemAtIndexToTop:index];
}
- (void)scrollItemAtIndexToVisible:(int)index
{
[_cell scrollItemAtIndexToVisible:index];
}
- (void)selectItemAtIndex:(int)index
{
[_cell selectItemAtIndex:index];
}
- (void)deselectItemAtIndex:(int)index
{
[_cell deselectItemAtIndex:index];
}
- (int)indexOfSelectedItem
{
return [_cell indexOfSelectedItem];
}
- (int)numberOfItems
{
return [_cell numberOfItems];
}
- (id)dataSource
{
return [_cell dataSource];
}
- (void)setDataSource:(id)aSource
{
[_cell setDataSource:aSource];
}
- (void)addItemWithObjectValue:(id)object
{
[_cell addItemWithObjectValue:object];
}
- (void)addItemsWithObjectValues:(NSArray *)objects
{
[_cell addItemsWithObjectValues:objects];
}
- (void)insertItemWithObjectValue:(id)object atIndex:(int)index
{
[_cell insertItemWithObjectValue:object atIndex:index];
}
- (void)removeItemWithObjectValue:(id)object
{
[_cell removeItemWithObjectValue:object];
}
- (void)removeItemAtIndex:(int)index
{
[_cell removeItemAtIndex:index];
}
- (void)removeAllItems
{
[_cell removeAllItems];
}
- (void)selectItemWithObjectValue:(id)object
{
[_cell selectItemWithObjectValue:object];
}
- (id)itemObjectValueAtIndex:(int)index
{
return [_cell itemObjectValueAtIndex:index];
}
- (id)objectValueOfSelectedItem
{
return [_cell objectValueOfSelectedItem];
}
- (int)indexOfItemWithObjectValue:(id)object
{
return [_cell indexOfItemWithObjectValue:object];
}
- (NSArray *)objectValues
{
return [_cell objectValues];
}
- (void)setCompletes:(BOOL)completes
{
[_cell setCompletes: completes];
}
- (BOOL)completes
{
return [_cell completes];
}
- (void) setDelegate: (id)anObject
{
[super setDelegate: anObject];
#define SET_DELEGATE_NOTIFICATION(notif_name) \
if ([_delegate respondsToSelector: @selector(comboBox##notif_name:)]) \
[nc addObserver: _delegate \
selector: @selector(comboBox##notif_name:) \
name: NSComboBox##notif_name##Notification object: self]
SET_DELEGATE_NOTIFICATION(SelectionDidChange);
SET_DELEGATE_NOTIFICATION(SelectionIsChanging);
SET_DELEGATE_NOTIFICATION(WillPopUp);
SET_DELEGATE_NOTIFICATION(WillDismiss);
}
// Overridden
- (void) mouseDown: (NSEvent*)theEvent
{
BOOL clicked;
// clicked is set to the value YES when the click occurs in the text cell
// and to the value NO when it occurs in the button cell
clicked = [_cell trackMouse: theEvent inRect: [self bounds]
ofView: self untilMouseUp: YES];
if (clicked)
[super mouseDown: theEvent];
}
@end