2001-12-17 16:51:51 +00:00
|
|
|
/** <title>NSComboBox</title>
|
1999-09-09 20:06:52 +00:00
|
|
|
|
|
|
|
Copyright (C) 1999 Free Software Foundation, Inc.
|
|
|
|
|
2001-12-17 16:51:51 +00:00
|
|
|
Author: Gerrit van Dyk <gerritvd@decillion.net>
|
1999-09-09 20:06:52 +00:00
|
|
|
Date: 1999
|
|
|
|
|
|
|
|
This file is part of the GNUstep GUI Library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
2007-10-29 21:16:17 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
1999-09-09 20:06:52 +00:00
|
|
|
License as published by the Free Software Foundation; either
|
2008-06-10 04:01:49 +00:00
|
|
|
version 2 of the License, or (at your option) any later version.
|
1999-09-09 20:06:52 +00:00
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2007-10-29 21:16:17 +00:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
1999-09-09 20:06:52 +00:00
|
|
|
|
2007-10-29 21:16:17 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
1999-09-09 20:06:52 +00:00
|
|
|
License along with this library; see the file COPYING.LIB.
|
2007-10-29 21:16:17 +00:00
|
|
|
If not, see <http://www.gnu.org/licenses/> or write to the
|
|
|
|
Free Software Foundation, 51 Franklin Street, Fifth Floor,
|
|
|
|
Boston, MA 02110-1301, USA.
|
1999-09-09 20:06:52 +00:00
|
|
|
*/
|
|
|
|
|
2011-03-04 11:33:22 +00:00
|
|
|
#import <Foundation/NSNotification.h>
|
|
|
|
#import <Foundation/NSString.h>
|
|
|
|
#import "AppKit/NSComboBox.h"
|
|
|
|
#import "AppKit/NSComboBoxCell.h"
|
|
|
|
#import "AppKit/NSEvent.h"
|
|
|
|
#import "AppKit/NSTextView.h"
|
1999-09-09 20:06:52 +00:00
|
|
|
|
2001-04-09 21:26:34 +00:00
|
|
|
/*
|
|
|
|
* Class variables
|
|
|
|
*/
|
|
|
|
static Class usedCellClass;
|
|
|
|
static Class comboBoxCellClass;
|
2001-06-09 23:33:47 +00:00
|
|
|
static NSNotificationCenter *nc;
|
|
|
|
|
2010-08-11 20:49:33 +00:00
|
|
|
/*
|
|
|
|
* Declaration of private cell method
|
|
|
|
*/
|
|
|
|
|
|
|
|
@interface NSComboBoxCell (GNUstepPrivate)
|
|
|
|
- (void) _performClickWithFrame: (NSRect)cellFrame
|
|
|
|
inView: (NSView *)controlView;
|
|
|
|
@end
|
|
|
|
|
2023-09-12 21:49:05 +00:00
|
|
|
/*
|
|
|
|
* Declaration of private NSTextField method
|
|
|
|
*/
|
|
|
|
|
|
|
|
@interface NSTextField (GNUstepPrivate)
|
|
|
|
- (BOOL)textView: (NSTextView*)textView doCommandBySelector: (SEL)command;
|
|
|
|
@end
|
|
|
|
|
2004-06-06 17:02:30 +00:00
|
|
|
/**
|
|
|
|
<unit>
|
|
|
|
<heading>Class Description</heading>
|
2004-08-08 19:09:57 +00:00
|
|
|
<p>An NSComboBox is what we can call a completion/choices box, derived from
|
2004-06-06 17:02:30 +00:00
|
|
|
NSTextField, it allows you to enter text like in a text field but also to click
|
2004-06-07 14:16:28 +00:00
|
|
|
in the ellipsis button (indicating the fact other user inputs are possible) on
|
2004-06-09 10:34:33 +00:00
|
|
|
the right of it to obtain a list of choices, you can use them as the text field
|
2004-06-06 17:02:30 +00:00
|
|
|
value by selecting a row in this list. You can also obtain direct completion
|
|
|
|
when it is enabled via <code>setCompletes:</code> to get a suggested text
|
2004-08-08 19:09:57 +00:00
|
|
|
field value updated as you type.</p>
|
|
|
|
<p>Like other NSControl classes, NSComboBox is a wrapper around a core piece which
|
2004-06-06 17:02:30 +00:00
|
|
|
implements the combo box behavior, a cell, which is in this case an
|
2004-08-08 19:09:57 +00:00
|
|
|
NSComboBoxCell.</p>
|
2004-06-06 17:02:30 +00:00
|
|
|
</unit>
|
|
|
|
*/
|
2001-04-09 21:26:34 +00:00
|
|
|
|
2004-08-08 19:09:57 +00:00
|
|
|
/**
|
|
|
|
<p>No special instructions to use NSComboBox or text to detail the implementation.</p>
|
|
|
|
*/
|
1999-09-09 20:06:52 +00:00
|
|
|
@implementation NSComboBox
|
|
|
|
|
2004-05-29 13:17:21 +00:00
|
|
|
+ (void) initialize
|
1999-09-09 20:06:52 +00:00
|
|
|
{
|
2004-06-06 17:02:30 +00:00
|
|
|
if (self == [NSComboBox class])
|
2001-04-09 21:26:34 +00:00
|
|
|
{
|
|
|
|
[self setVersion: 1];
|
|
|
|
comboBoxCellClass = [NSComboBoxCell class];
|
|
|
|
usedCellClass = comboBoxCellClass;
|
2001-06-09 23:33:47 +00:00
|
|
|
nc = [NSNotificationCenter defaultCenter];
|
2001-04-09 21:26:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setting the Cell class
|
|
|
|
*/
|
|
|
|
+ (Class) cellClass
|
|
|
|
{
|
|
|
|
return usedCellClass;
|
1999-09-09 20:06:52 +00:00
|
|
|
}
|
|
|
|
|
2001-04-09 21:26:34 +00:00
|
|
|
+ (void) setCellClass: (Class)factoryId
|
1999-09-09 20:06:52 +00:00
|
|
|
{
|
2001-04-09 21:26:34 +00:00
|
|
|
usedCellClass = factoryId ? factoryId : comboBoxCellClass;
|
1999-09-09 20:06:52 +00:00
|
|
|
}
|
|
|
|
|
2004-06-06 17:02:30 +00:00
|
|
|
/**
|
|
|
|
* Returns YES when the combo box cell displays a vertical scroller for its
|
|
|
|
* list, returns NO otherwise.
|
|
|
|
* Take note that the scroller will be displayed even when the sum of the items
|
|
|
|
* height in the list is inferior to the minimal height of the list displayed
|
|
|
|
* area.
|
|
|
|
*/
|
1999-09-09 20:06:52 +00:00
|
|
|
- (BOOL)hasVerticalScroller
|
|
|
|
{
|
2001-04-09 21:26:34 +00:00
|
|
|
return [_cell hasVerticalScroller];
|
1999-09-09 20:06:52 +00:00
|
|
|
}
|
|
|
|
|
2004-06-06 17:02:30 +00:00
|
|
|
/**
|
|
|
|
* Sets whether the combo box cell list displays a vertical scroller, by default
|
|
|
|
* it is the case. When <var>flag</var> is NO and the combo cell list has more
|
|
|
|
* items (either in its default list or from its data source) than the number
|
|
|
|
* returned by <code>numberOfVisibleItems</code>, only a subset of them will be
|
|
|
|
* displayed. Uses scroll related methods to position this subset in the combo
|
|
|
|
* box cell list.
|
|
|
|
* Take note that the scroller will be displayed even when the sum of the items
|
|
|
|
* height in the list is inferior to the minimal height of the list displayed
|
|
|
|
* area.
|
|
|
|
*/
|
1999-09-09 20:06:52 +00:00
|
|
|
- (void)setHasVerticalScroller:(BOOL)flag
|
|
|
|
{
|
2001-04-09 21:26:34 +00:00
|
|
|
[_cell setHasVerticalScroller:flag];
|
1999-09-09 20:06:52 +00:00
|
|
|
}
|
|
|
|
|
2004-06-06 17:02:30 +00:00
|
|
|
/**
|
|
|
|
* Returns the width and the height (as the values of an NSSize variable)
|
|
|
|
* between each item of the combo box cell list.
|
|
|
|
*/
|
1999-09-09 20:06:52 +00:00
|
|
|
- (NSSize)intercellSpacing
|
|
|
|
{
|
2001-04-09 21:26:34 +00:00
|
|
|
return [_cell intercellSpacing];
|
1999-09-09 20:06:52 +00:00
|
|
|
}
|
|
|
|
|
2004-06-06 17:02:30 +00:00
|
|
|
/**
|
|
|
|
* Sets the width and the height between each item of the combo box cell list to
|
|
|
|
* the values in <var>aSize</var>.
|
|
|
|
*/
|
1999-09-09 20:06:52 +00:00
|
|
|
- (void)setIntercellSpacing:(NSSize)aSize
|
|
|
|
{
|
2001-04-09 21:26:34 +00:00
|
|
|
[_cell setIntercellSpacing:aSize];
|
1999-09-09 20:06:52 +00:00
|
|
|
}
|
|
|
|
|
2004-06-06 17:02:30 +00:00
|
|
|
/**
|
|
|
|
* Returns the height of the items in the combo box cell list.
|
|
|
|
*/
|
2013-02-17 00:49:04 +00:00
|
|
|
- (CGFloat)itemHeight
|
1999-09-09 20:06:52 +00:00
|
|
|
{
|
2001-04-09 21:26:34 +00:00
|
|
|
return [_cell itemHeight];
|
1999-09-09 20:06:52 +00:00
|
|
|
}
|
|
|
|
|
2004-06-06 17:02:30 +00:00
|
|
|
/**
|
|
|
|
* Sets the height of the items in the combo box cell list to
|
|
|
|
* <var>itemHeight</var>.
|
|
|
|
*/
|
2013-02-17 00:49:04 +00:00
|
|
|
- (void)setItemHeight:(CGFloat)itemHeight
|
1999-09-09 20:06:52 +00:00
|
|
|
{
|
2001-04-09 21:26:34 +00:00
|
|
|
[_cell setItemHeight:itemHeight];
|
1999-09-09 20:06:52 +00:00
|
|
|
}
|
|
|
|
|
2004-06-06 17:02:30 +00:00
|
|
|
/**
|
|
|
|
* Returns the maximum number of allowed items to be displayed in the combo box
|
|
|
|
* cell list.
|
|
|
|
*/
|
2013-01-30 12:43:27 +00:00
|
|
|
- (NSInteger)numberOfVisibleItems
|
1999-09-09 20:06:52 +00:00
|
|
|
{
|
2001-04-09 21:26:34 +00:00
|
|
|
return [_cell numberOfVisibleItems];
|
1999-09-09 20:06:52 +00:00
|
|
|
}
|
|
|
|
|
2004-06-06 17:02:30 +00:00
|
|
|
/**
|
|
|
|
* Sets the maximum number of allowed items to be displayed in the combo box
|
|
|
|
* cell list.
|
|
|
|
*/
|
2013-01-30 12:43:27 +00:00
|
|
|
- (void)setNumberOfVisibleItems:(NSInteger)visibleItems
|
1999-09-09 20:06:52 +00:00
|
|
|
{
|
2001-04-09 21:26:34 +00:00
|
|
|
[_cell setNumberOfVisibleItems:visibleItems];
|
1999-09-09 20:06:52 +00:00
|
|
|
}
|
|
|
|
|
2004-06-06 17:02:30 +00:00
|
|
|
/**
|
|
|
|
* Marks the combo box cell in order to have its items list reloaded in the
|
|
|
|
* case it uses a data source, and to have it redisplayed.
|
|
|
|
*/
|
1999-09-09 20:06:52 +00:00
|
|
|
- (void)reloadData
|
|
|
|
{
|
2001-04-09 21:26:34 +00:00
|
|
|
[_cell reloadData];
|
1999-09-09 20:06:52 +00:00
|
|
|
}
|
|
|
|
|
2004-06-06 17:02:30 +00:00
|
|
|
/**
|
|
|
|
* Informs the combo box cell that the number of items in its data source has
|
|
|
|
* changed, in order to permit to the scrollers in its displayed list being
|
|
|
|
* updated without needing the reload of the data.
|
|
|
|
* It is recommended to use this method with a data source that continually
|
|
|
|
* receives data in the background, to keep the the combo box cell responsive to
|
|
|
|
* the user while the data is received.
|
|
|
|
* Take a look at the <code>NSComboBoxDataSource</code> informal protocol
|
|
|
|
* specification to know more on the messages NSComboBox sends to its data
|
|
|
|
* source.
|
|
|
|
*/
|
1999-09-09 20:06:52 +00:00
|
|
|
- (void)noteNumberOfItemsChanged
|
|
|
|
{
|
2001-04-09 21:26:34 +00:00
|
|
|
[_cell noteNumberOfItemsChanged];
|
1999-09-09 20:06:52 +00:00
|
|
|
}
|
|
|
|
|
2004-06-06 17:02:30 +00:00
|
|
|
/**
|
|
|
|
* Returns YES when the combo box cell uses a data source (which is external) to
|
|
|
|
* populate its items list, otherwise returns NO in the case it uses its default
|
|
|
|
* list.
|
|
|
|
*/
|
1999-09-09 20:06:52 +00:00
|
|
|
- (BOOL)usesDataSource
|
|
|
|
{
|
2001-04-09 21:26:34 +00:00
|
|
|
return [_cell usesDataSource];
|
1999-09-09 20:06:52 +00:00
|
|
|
}
|
|
|
|
|
2004-06-06 17:02:30 +00:00
|
|
|
/**
|
|
|
|
* Sets according to <var>flag</var> whether the combo box cell uses a data
|
|
|
|
* source (which is external) to populate its items list.
|
|
|
|
*/
|
1999-09-09 20:06:52 +00:00
|
|
|
- (void)setUsesDataSource:(BOOL)flag
|
|
|
|
{
|
2001-04-09 21:26:34 +00:00
|
|
|
[_cell setUsesDataSource:flag];
|
1999-09-09 20:06:52 +00:00
|
|
|
}
|
|
|
|
|
2004-06-06 17:02:30 +00:00
|
|
|
/**
|
|
|
|
* Scrolls the combo box cell list vertically in order to have the item at
|
|
|
|
* <var>index</var> in the closest position relative to the top. There is no
|
|
|
|
* need to have the list displayed when this method is invoked.
|
|
|
|
*/
|
2013-01-30 12:43:27 +00:00
|
|
|
- (void)scrollItemAtIndexToTop:(NSInteger)index
|
1999-09-09 20:06:52 +00:00
|
|
|
{
|
2001-04-09 21:26:34 +00:00
|
|
|
[_cell scrollItemAtIndexToTop:index];
|
1999-09-09 20:06:52 +00:00
|
|
|
}
|
|
|
|
|
2004-06-06 17:02:30 +00:00
|
|
|
/**
|
|
|
|
* Scrolls the combo box cell list vertically in order to have the item at
|
|
|
|
* <var>index</var> visible. There is no need to have the list displayed when
|
|
|
|
* this method is invoked.
|
|
|
|
*/
|
2013-01-30 12:43:27 +00:00
|
|
|
- (void)scrollItemAtIndexToVisible:(NSInteger)index
|
1999-09-09 20:06:52 +00:00
|
|
|
{
|
2001-04-09 21:26:34 +00:00
|
|
|
[_cell scrollItemAtIndexToVisible:index];
|
1999-09-09 20:06:52 +00:00
|
|
|
}
|
|
|
|
|
2004-06-06 17:02:30 +00:00
|
|
|
/**
|
|
|
|
* Selects the combo box cell list row at <var>index</var>.
|
|
|
|
* Take note no changes occurs in the combo box cell list when this method is
|
|
|
|
* called.
|
|
|
|
* Posts an NSComboBoxSelectionDidChangeNotification to the default notification
|
|
|
|
* center when there is a new selection different from the previous one.
|
|
|
|
*/
|
2013-01-30 12:43:27 +00:00
|
|
|
- (void)selectItemAtIndex:(NSInteger)index
|
1999-09-09 20:06:52 +00:00
|
|
|
{
|
2001-04-09 21:26:34 +00:00
|
|
|
[_cell selectItemAtIndex:index];
|
1999-09-09 20:06:52 +00:00
|
|
|
}
|
|
|
|
|
2004-06-06 17:02:30 +00:00
|
|
|
/**
|
|
|
|
* Deselects the combo box cell list row at <var>index</var> in the case this
|
|
|
|
* row is selected.
|
|
|
|
* Posts an NSComboBoxSelectionDidChangeNotification to the default notification
|
|
|
|
* center, when there is a new selection.
|
|
|
|
*/
|
2013-01-30 12:43:27 +00:00
|
|
|
- (void)deselectItemAtIndex:(NSInteger)index
|
1999-09-09 20:06:52 +00:00
|
|
|
{
|
2001-04-09 21:26:34 +00:00
|
|
|
[_cell deselectItemAtIndex:index];
|
1999-09-09 20:06:52 +00:00
|
|
|
}
|
|
|
|
|
2004-06-06 17:02:30 +00:00
|
|
|
/**
|
|
|
|
* Returns the index of the selected item in the combo box cell list or -1 when
|
|
|
|
* there is no selection, the selected item can be related to the data source
|
|
|
|
* object in the case <code>usesDataSource</code> returns YES else to the
|
|
|
|
* default items list.
|
|
|
|
*/
|
2013-01-30 12:43:27 +00:00
|
|
|
- (NSInteger)indexOfSelectedItem
|
1999-09-09 20:06:52 +00:00
|
|
|
{
|
2001-04-09 21:26:34 +00:00
|
|
|
return [_cell indexOfSelectedItem];
|
1999-09-09 20:06:52 +00:00
|
|
|
}
|
|
|
|
|
2004-06-06 17:02:30 +00:00
|
|
|
/**
|
|
|
|
* Returns the number of items in the the combo box cell list, the numbers of
|
|
|
|
* items can be be related to the data source object in the case
|
|
|
|
* <code>usesDataSource</code> returns YES else to the default items list.
|
|
|
|
*/
|
2013-01-30 12:43:27 +00:00
|
|
|
- (NSInteger)numberOfItems
|
1999-09-09 20:06:52 +00:00
|
|
|
{
|
2001-04-09 21:26:34 +00:00
|
|
|
return [_cell numberOfItems];
|
1999-09-09 20:06:52 +00:00
|
|
|
}
|
|
|
|
|
2004-06-06 17:02:30 +00:00
|
|
|
/**
|
|
|
|
* Returns the combo box cell data source object which is reponsible to provide
|
|
|
|
* the data to be displayed. To know how to implement a data source object,
|
|
|
|
* take a look at the NSComboBoxDataSource informal protocol description. In
|
|
|
|
* the case <code>usesDataSource</code> returns NO, this method logs a warning.
|
|
|
|
*/
|
1999-09-09 20:06:52 +00:00
|
|
|
- (id)dataSource
|
|
|
|
{
|
2001-04-09 21:26:34 +00:00
|
|
|
return [_cell dataSource];
|
1999-09-09 20:06:52 +00:00
|
|
|
}
|
|
|
|
|
2004-06-06 17:02:30 +00:00
|
|
|
/**
|
|
|
|
* Sets the combo box cell data source to <var>aSource</var>. Just calling this
|
|
|
|
* method doesn't set <code>usesDataSource</code> to return YES, you must call
|
|
|
|
* <code>setUsesDataSource:</code> with YES before or a warning will be logged.
|
|
|
|
* To know how to implement a data source objects, take a look at the
|
|
|
|
* NSComboBoxDataSource informal protocol description. When <var>aSource</var>
|
|
|
|
* doesn't respond to the methods <code>numberOfItemsInComboBox:</code>
|
|
|
|
* <code>comboBox:objectValueForItemAtIndex:</code>, this method
|
|
|
|
* logs a warning.
|
|
|
|
*/
|
1999-09-09 20:06:52 +00:00
|
|
|
- (void)setDataSource:(id)aSource
|
|
|
|
{
|
2001-04-09 21:26:34 +00:00
|
|
|
[_cell setDataSource:aSource];
|
1999-09-09 20:06:52 +00:00
|
|
|
}
|
|
|
|
|
2004-06-06 17:02:30 +00:00
|
|
|
/**
|
|
|
|
* Adds an item to the combo box cell default items list which is used when
|
|
|
|
* <code>usesDataSource</code> returns NO. In the case
|
|
|
|
* <code>usesDataSource</code> returns YES, this method logs a warning.
|
|
|
|
*/
|
1999-09-09 20:06:52 +00:00
|
|
|
- (void)addItemWithObjectValue:(id)object
|
|
|
|
{
|
2001-04-09 21:26:34 +00:00
|
|
|
[_cell addItemWithObjectValue:object];
|
1999-09-09 20:06:52 +00:00
|
|
|
}
|
|
|
|
|
2004-06-06 17:02:30 +00:00
|
|
|
/**
|
|
|
|
* Adds several items in an array to the combo box cell default items list which
|
|
|
|
* is used when <code>usesDataSource</code> returns NO. In the case
|
|
|
|
* <code>usesDataSource</code> returns YES, this method logs a warning.
|
|
|
|
*/
|
1999-09-09 20:06:52 +00:00
|
|
|
- (void)addItemsWithObjectValues:(NSArray *)objects
|
|
|
|
{
|
2001-04-09 21:26:34 +00:00
|
|
|
[_cell addItemsWithObjectValues:objects];
|
1999-09-09 20:06:52 +00:00
|
|
|
}
|
|
|
|
|
2004-06-06 17:02:30 +00:00
|
|
|
/**
|
|
|
|
* Inserts an item in the combo box cell default items list which
|
|
|
|
* is used when <code>usesDataSource</code> returns NO. In the case
|
|
|
|
* <code>usesDataSource</code> returns YES, this method logs a warning.
|
|
|
|
*/
|
2013-01-30 12:43:27 +00:00
|
|
|
- (void)insertItemWithObjectValue:(id)object atIndex:(NSInteger)index
|
1999-09-09 20:06:52 +00:00
|
|
|
{
|
2001-04-09 21:26:34 +00:00
|
|
|
[_cell insertItemWithObjectValue:object atIndex:index];
|
1999-09-09 20:06:52 +00:00
|
|
|
}
|
|
|
|
|
2004-06-06 17:02:30 +00:00
|
|
|
/**
|
|
|
|
* Removes an item in the combo box cell default items list which
|
|
|
|
* is used when <code>usesDataSource</code> returns NO. In the case
|
|
|
|
* <code>usesDataSource</code> returns YES, this method logs a warning.
|
|
|
|
*/
|
1999-09-09 20:06:52 +00:00
|
|
|
- (void)removeItemWithObjectValue:(id)object
|
|
|
|
{
|
2001-04-09 21:26:34 +00:00
|
|
|
[_cell removeItemWithObjectValue:object];
|
1999-09-09 20:06:52 +00:00
|
|
|
}
|
|
|
|
|
2004-06-06 17:02:30 +00:00
|
|
|
/**
|
|
|
|
* Removes the item with the specified <var>index</var> in the combo box cell
|
|
|
|
* default items list which is used when <code>usesDataSource</code> returns NO.
|
|
|
|
* In the case <code>usesDataSource</code> returns YES, this method logs a warning.
|
|
|
|
*/
|
2013-01-30 12:43:27 +00:00
|
|
|
- (void)removeItemAtIndex:(NSInteger)index
|
1999-09-09 20:06:52 +00:00
|
|
|
{
|
2001-04-09 21:26:34 +00:00
|
|
|
[_cell removeItemAtIndex:index];
|
1999-09-09 20:06:52 +00:00
|
|
|
}
|
|
|
|
|
2004-06-06 17:02:30 +00:00
|
|
|
/**
|
|
|
|
* Removes all the items in the combo box cell default items list which is used
|
|
|
|
* when <code>usesDataSource</code> returns NO. In the case
|
|
|
|
* <code>usesDataSource</code> returns YES, this method logs a warning.
|
|
|
|
*/
|
1999-09-09 20:06:52 +00:00
|
|
|
- (void)removeAllItems
|
|
|
|
{
|
2001-04-09 21:26:34 +00:00
|
|
|
[_cell removeAllItems];
|
1999-09-09 20:06:52 +00:00
|
|
|
}
|
|
|
|
|
2004-06-06 17:02:30 +00:00
|
|
|
/**
|
|
|
|
* Selects the first item in the default combo box cell list which is equal to
|
|
|
|
* <var>object</var>. In the case <code>usesDataSource</code> returns YES, this
|
|
|
|
* method logs a warning.
|
|
|
|
* Take note that this method doesn't update the text field part value.
|
|
|
|
* Posts an NSComboBoxSelectionDidChange notification to the default
|
|
|
|
* notification center when the new selection is different than the previous
|
|
|
|
* one.
|
|
|
|
*/
|
1999-09-09 20:06:52 +00:00
|
|
|
- (void)selectItemWithObjectValue:(id)object
|
|
|
|
{
|
2001-04-09 21:26:34 +00:00
|
|
|
[_cell selectItemWithObjectValue:object];
|
1999-09-09 20:06:52 +00:00
|
|
|
}
|
|
|
|
|
2004-06-06 17:02:30 +00:00
|
|
|
/**
|
|
|
|
* Returns the object value at <var>index</var> within combo box cell default
|
|
|
|
* items list. When the index is beyond the end of the list, an NSRangeException is
|
|
|
|
* raised. In the case <code>usesDataSource</code> returns YES, this method logs
|
|
|
|
* a warning.
|
|
|
|
*/
|
2013-01-30 12:43:27 +00:00
|
|
|
- (id)itemObjectValueAtIndex:(NSInteger)index
|
1999-09-09 20:06:52 +00:00
|
|
|
{
|
2001-04-09 21:26:34 +00:00
|
|
|
return [_cell itemObjectValueAtIndex:index];
|
1999-09-09 20:06:52 +00:00
|
|
|
}
|
|
|
|
|
2004-06-06 17:02:30 +00:00
|
|
|
/**
|
|
|
|
* Returns the object value of the selected item in the combo box cell default
|
|
|
|
* items list or nil when there is no selection. In the case
|
|
|
|
* <code>usesDataSource</code> returns YES, this method logs a warning.
|
|
|
|
*/
|
1999-09-09 20:06:52 +00:00
|
|
|
- (id)objectValueOfSelectedItem
|
|
|
|
{
|
2001-04-09 21:26:34 +00:00
|
|
|
return [_cell objectValueOfSelectedItem];
|
1999-09-09 20:06:52 +00:00
|
|
|
}
|
|
|
|
|
2004-06-06 17:02:30 +00:00
|
|
|
/**
|
|
|
|
* Returns the lowest index associated with a value in the combo box
|
|
|
|
* cell default items list, which is equal to <var>object</var>, and returns
|
|
|
|
* NSNotFound when there is no such value. In the case
|
|
|
|
* <code>usesDataSource</code> returns YES, this method logs a warning.
|
|
|
|
*/
|
2013-01-30 12:43:27 +00:00
|
|
|
- (NSInteger)indexOfItemWithObjectValue:(id)object
|
1999-09-09 20:06:52 +00:00
|
|
|
{
|
2001-04-09 21:26:34 +00:00
|
|
|
return [_cell indexOfItemWithObjectValue:object];
|
1999-09-09 20:06:52 +00:00
|
|
|
}
|
|
|
|
|
2004-06-06 17:02:30 +00:00
|
|
|
/**
|
|
|
|
* Returns the combo box cell default items list in an array.
|
|
|
|
*/
|
1999-09-09 20:06:52 +00:00
|
|
|
- (NSArray *)objectValues
|
|
|
|
{
|
2001-04-09 21:26:34 +00:00
|
|
|
return [_cell objectValues];
|
|
|
|
}
|
|
|
|
|
2004-06-07 14:16:28 +00:00
|
|
|
/**
|
|
|
|
* Returns YES when the combo box cell automatic completion is active, returns
|
|
|
|
* NO otherwise.
|
|
|
|
* Take a look at the <code>setCompletes:</code> method documentation to know
|
|
|
|
* how the automatic completion works.
|
|
|
|
*/
|
|
|
|
- (BOOL)completes
|
|
|
|
{
|
|
|
|
return [_cell completes];
|
|
|
|
}
|
|
|
|
|
2004-06-06 17:02:30 +00:00
|
|
|
/**
|
|
|
|
* Sets whether the combo box cell automatic completion is active or not.
|
|
|
|
* The automatic completion tries to complete what the user types in the text
|
|
|
|
* field part, it tries to complete only when the the user adds characters at
|
|
|
|
* the end of the string, not when it deletes characters or when the insertion
|
|
|
|
* point precedes the end of the string.
|
|
|
|
* To do the automatic completion, the <code>completedString:</code> method is
|
|
|
|
* called, and when the returned string is longer than the current one in the text
|
|
|
|
* field, the completion occurs and the completed part gets selected.
|
|
|
|
*/
|
2001-04-09 21:26:34 +00:00
|
|
|
- (void)setCompletes:(BOOL)completes
|
|
|
|
{
|
|
|
|
[_cell setCompletes: completes];
|
|
|
|
}
|
|
|
|
|
2007-07-31 21:42:30 +00:00
|
|
|
- (BOOL) isButtonBordered
|
|
|
|
{
|
|
|
|
return [_cell isButtonBordered];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setButtonBordered:(BOOL)flag
|
|
|
|
{
|
|
|
|
[_cell setButtonBordered: flag];
|
|
|
|
}
|
|
|
|
|
2001-06-09 23:33:47 +00:00
|
|
|
- (void) setDelegate: (id)anObject
|
|
|
|
{
|
|
|
|
[super setDelegate: anObject];
|
|
|
|
|
|
|
|
#define SET_DELEGATE_NOTIFICATION(notif_name) \
|
|
|
|
if ([_delegate respondsToSelector: @selector(comboBox##notif_name:)]) \
|
|
|
|
[nc addObserver: _delegate \
|
2004-05-29 13:17:21 +00:00
|
|
|
selector: @selector(comboBox##notif_name:) \
|
|
|
|
name: NSComboBox##notif_name##Notification object: self]
|
2001-06-09 23:33:47 +00:00
|
|
|
|
|
|
|
SET_DELEGATE_NOTIFICATION(SelectionDidChange);
|
|
|
|
SET_DELEGATE_NOTIFICATION(SelectionIsChanging);
|
|
|
|
SET_DELEGATE_NOTIFICATION(WillPopUp);
|
|
|
|
SET_DELEGATE_NOTIFICATION(WillDismiss);
|
|
|
|
}
|
|
|
|
|
1999-09-09 20:06:52 +00:00
|
|
|
// Overridden
|
2004-05-29 13:17:21 +00:00
|
|
|
- (void) mouseDown: (NSEvent*)theEvent
|
|
|
|
{
|
2004-08-13 22:07:06 +00:00
|
|
|
BOOL buttonClicked;
|
2004-08-13 23:28:50 +00:00
|
|
|
// buttonClicked is set to the value NO when the click occurs in the text cell
|
|
|
|
// and to the value YES when it occurs in the button cell.
|
2004-05-29 13:17:21 +00:00
|
|
|
|
2004-08-13 22:07:06 +00:00
|
|
|
buttonClicked = [_cell trackMouse: theEvent inRect: [self bounds]
|
2004-05-29 13:17:21 +00:00
|
|
|
ofView: self untilMouseUp: YES];
|
|
|
|
|
2004-08-13 22:07:06 +00:00
|
|
|
if (!buttonClicked)
|
2004-05-29 13:17:21 +00:00
|
|
|
[super mouseDown: theEvent];
|
1999-09-09 20:06:52 +00:00
|
|
|
}
|
|
|
|
|
2010-08-11 20:49:33 +00:00
|
|
|
- (BOOL) textView: (NSTextView *)textView doCommandBySelector: (SEL)command
|
|
|
|
{
|
|
|
|
if ([super textView: textView doCommandBySelector: command])
|
|
|
|
return YES;
|
2010-09-09 23:50:38 +00:00
|
|
|
if (sel_isEqual(command, @selector(moveDown:)))
|
2010-08-11 20:49:33 +00:00
|
|
|
{
|
|
|
|
[_cell _performClickWithFrame: [self bounds] inView: self];
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2004-06-09 10:34:33 +00:00
|
|
|
- (void) setFrame: (NSRect)frame
|
|
|
|
{
|
|
|
|
NSRect rect = NSMakeRect(frame.origin.x, frame.origin.y, frame.size.width, 21);
|
|
|
|
// FIX ME: We shouldn't harcode the height value
|
|
|
|
|
|
|
|
[super setFrame: rect];
|
|
|
|
}
|
|
|
|
|
1999-09-09 20:06:52 +00:00
|
|
|
@end
|