1/** <title>NSTokenField</title> 2 3 <abstract> 4 Token field control class for token entry. The default token is ",". 5 </abstract> 6 7 Copyright (C) 2008 Free Software Foundation, Inc. 8 9 Author: Gregory Casamento <greg.casamento@gmail.com> 10 Date: July 2008 11 12 This file is part of the GNUstep GUI Library. 13 14 This library is free software; you can redistribute it and/or 15 modify it under the terms of the GNU Lesser General Public 16 License as published by the Free Software Foundation; either 17 version 2 of the License, or (at your option) any later version. 18 19 This library is distributed in the hope that it will be useful, 20 but WITHOUT ANY WARRANTY; without even the implied warranty of 21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 Lesser General Public License for more details. 23 24 You should have received a copy of the GNU Lesser General Public 25 License along with this library; see the file COPYING.LIB. 26 If not, see <http://www.gnu.org/licenses/> or write to the 27 Free Software Foundation, 51 Franklin Street, Fifth Floor, 28 Boston, MA 02110-1301, USA. 29*/ 30 31#include "config.h" 32 33#import <Foundation/NSNotification.h> 34#import "AppKit/NSApplication.h" 35#import "AppKit/NSCursor.h" 36#import "AppKit/NSGraphics.h" 37#import "AppKit/NSTokenField.h" 38#import "AppKit/NSTokenFieldCell.h" 39#import "AppKit/NSWindow.h" 40#import "AppKit/NSKeyValueBinding.h" 41#import "GSBindingHelpers.h" 42 43static NSNotificationCenter *nc = nil; 44 45/* 46 * Class variables 47 */ 48static Class usedCellClass; 49static Class tokenFieldCellClass; 50 51@implementation NSTokenField 52 53// 54// Class methods 55// 56+ (void) initialize 57{ 58 if (self == [NSTokenField class]) 59 { 60 [self setVersion: 1]; 61 tokenFieldCellClass = [NSTokenFieldCell class]; 62 usedCellClass = tokenFieldCellClass; 63 nc = [NSNotificationCenter defaultCenter]; 64 65 [self exposeBinding: NSEditableBinding]; 66 [self exposeBinding: NSTextColorBinding]; 67 } 68} 69 70- (id) initWithFrame: (NSRect)frame 71{ 72 if((self = [super initWithFrame: frame]) == nil) 73 { 74 return nil; 75 } 76 77 // initialize... 78 [_cell setTokenStyle: NSDefaultTokenStyle]; 79 [_cell setCompletionDelay: [_cell defaultCompletionDelay]]; 80 [_cell setTokenizingCharacterSet: [_cell defaultTokenizingCharacterSet]]; 81 82 return self; 83} 84 85/* 86 * Setting the Cell class 87 */ 88+ (Class) cellClass 89{ 90 return usedCellClass; 91} 92 93+ (void) setCellClass: (Class)factoryId 94{ 95 usedCellClass = factoryId ? factoryId : tokenFieldCellClass; 96} 97 98// Style... 99- (NSTokenStyle)tokenStyle 100{ 101 return [_cell tokenStyle]; 102} 103 104- (void)setTokenStyle:(NSTokenStyle)style 105{ 106 [_cell setTokenStyle: style]; 107} 108 109// Completion delay... 110+ (NSTimeInterval)defaultCompletionDelay 111{ 112 return [usedCellClass defaultCompletionDelay]; 113} 114 115- (NSTimeInterval)completionDelay 116{ 117 return [_cell completionDelay]; 118} 119 120- (void)setCompletionDelay:(NSTimeInterval)delay 121{ 122 [_cell setCompletionDelay: delay]; 123} 124 125// Character set... 126+ (NSCharacterSet *)defaultTokenizingCharacterSet 127{ 128 return [usedCellClass defaultTokenizingCharacterSet]; 129} 130 131- (void)setTokenizingCharacterSet:(NSCharacterSet *)characterSet 132{ 133 [_cell setTokenizingCharacterSet: characterSet]; 134} 135 136- (NSCharacterSet *)tokenizingCharacterSet 137{ 138 return [_cell tokenizingCharacterSet]; 139} 140@end 141