Debian Codegraph @

src/af/xap/cocoa/xap_Cocoa_NSTableUtils.cpp

raw
1 /* AbiWord
2 * Copyright (C) 2002-2003, 2009 Hubert Figuiere
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301 USA.
18 */
19
20 #include "ut_types.h"
21 #import "xap_CocoaCompat.h"
22 #import "xap_Cocoa_NSTableUtils.h"
23
24
25 @implementation XAP_StringListDataSource
26
27
28
29 - (id)init
30 {
31 if (![super init]) {
32 return nil;
33 }
34 _array = [[NSMutableArray alloc] init];
35 return self;
36 }
37
38 - (oneway void)dealloc
39 {
40 [_array release];
41 [super dealloc];
42 }
43
44
45 /* NSTableDataSource */
46 - (int)numberOfRowsInTableView:(NSTableView *)tableView
47 {
48 UT_UNUSED(tableView);
49 return [_array count];
50 }
51
52
53 - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row
54 {
55 UT_UNUSED(tableView);
56 UT_UNUSED(tableColumn);
57 return [_array objectAtIndex:row];
58 }
59
60 - (void)insertString:(NSString*)string atIndex:(int)index
61 {
62 [_array insertObject:string atIndex:index];
63 }
64
65 - (void)addString:(NSString*)string
66 {
67 [_array addObject:string];
68 }
69
70 - (void)addCString:(const char *)string
71 {
72 NSString *str = [[NSString alloc] initWithUTF8String:string];
73 [_array addObject:str];
74 [str release];
75 }
76
77 - (int)rowWithCString:(const char *)cString
78 {
79 NSString *string = [[NSString alloc] initWithUTF8String:cString];
80 NSUInteger idx = [_array indexOfObject:string];
81 [string release];
82 if (idx == NSNotFound) {
83 return -1;
84 }
85 return idx;
86 }
87
88 - (void)removeAllStrings
89 {
90 [_array removeAllObjects];
91 }
92
93 - (NSArray*)array
94 {
95 return _array;
96 }
97
98
99 - (void)loadFontList
100 {
101 [_array removeAllObjects];
102 [_array addObjectsFromArray:
103 [[[NSFontManager sharedFontManager] availableFontFamilies]
104 sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]];
105 }
106
107
108 @end