1//-------------------------------------------------------------------------
2/*
3 Copyright (C) 2013 Jonathon Fowler <jf@jonof.id.au>
4
5 This file is part of JFShadowWarrior
6
7 Duke Nukem 3D is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
16 See the GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21 */
22//-------------------------------------------------------------------------
23
24#import <Cocoa/Cocoa.h>
25
26#include "grpscan.h"
27#import "GameListSource.h"
28
29@implementation GameListSource
30- (id)tableView:(NSTableView *)aTableView
31        objectValueForTableColumn:(NSTableColumn *)aTableColumn
32            row:(NSInteger)rowIndex
33{
34    int row;
35    struct grpfile *fg = foundgrps;
36
37    for (row = 0; row < rowIndex && fg; fg = fg->next) {
38        if (fg->ref) row++;
39    }
40    if (!fg) {
41        return nil;
42    }
43    switch ([[aTableColumn identifier] intValue]) {
44        case 0:	// name column
45            if (fg->ref) {
46                return [NSString stringWithUTF8String: fg->ref->name];
47            } else {
48                return @"Unknown game";
49            }
50        case 1:	// grp column
51            return [NSString stringWithUTF8String: fg->name];
52        case 2: // hidden column pointing to the grpfile entry.
53            return [NSValue valueWithPointer: fg];
54        default:
55            return nil;
56    }
57}
58
59- (int)numberOfRowsInTableView:(NSTableView *)aTableView
60{
61    int count = 0;
62    struct grpfile *fg = foundgrps;
63
64    for (count = 0, fg = foundgrps; fg; fg = fg->next) {
65        if (fg->ref) count++;
66    }
67    return count;
68}
69
70- (int)indexForGrp:(struct grpfile *)grpFile
71{
72    int index;
73    struct grpfile *fg;
74
75    for (fg = foundgrps, index = 0; fg; fg = fg->next) {
76        if (fg == grpFile) return index;
77        if (fg->ref) index++;
78    }
79    return -1;
80}
81@end
82
83