1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
|
/** <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/NSApplication.h>
#include <AppKit/NSComboBox.h>
#include <AppKit/NSComboBoxCell.h>
@interface NSObject(MouseUpping)
- (NSEvent *)_mouseUpEvent;
@end
/*
* Class variables
*/
static Class usedCellClass;
static Class comboBoxCellClass;
static NSNotificationCenter *nc;
@implementation NSComboBox
+ (void)initialize
{
if (self == [NSComboBox class])
{
[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
{
NSEvent *cEvent;
[_cell trackMouse: theEvent inRect: [self bounds]
ofView: self untilMouseUp: YES];
if ([_cell respondsToSelector: @selector(_mouseUpEvent)])
cEvent = [_cell _mouseUpEvent];
else
cEvent = nil;
if ([_cell isSelectable])
{
if (!cEvent)
cEvent = [NSApp currentEvent];
if ([cEvent type] == NSLeftMouseUp &&
([cEvent windowNumber] == [[self window] windowNumber]))
[NSApp postEvent: cEvent atStart: NO];
[super mouseDown: theEvent];
}
}
@end
|